From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0CEAAC3DA78 for ; Sun, 15 Jan 2023 23:14:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3422A6B0071; Sun, 15 Jan 2023 18:14:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2F1496B0072; Sun, 15 Jan 2023 18:14:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1E08F6B0073; Sun, 15 Jan 2023 18:14:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 0DC846B0071 for ; Sun, 15 Jan 2023 18:14:24 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id CAE1F16041C for ; Sun, 15 Jan 2023 23:14:23 +0000 (UTC) X-FDA: 80358589206.12.68DE276 Received: from mail-vs1-f43.google.com (mail-vs1-f43.google.com [209.85.217.43]) by imf24.hostedemail.com (Postfix) with ESMTP id 5558818000E for ; Sun, 15 Jan 2023 23:14:21 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="Im/CuRNv"; spf=pass (imf24.hostedemail.com: domain of yuzhao@google.com designates 209.85.217.43 as permitted sender) smtp.mailfrom=yuzhao@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673824461; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=86dZ2QP+sHr0Jg65uUt9BrhUPIsdfEcbXYkErF8fpe8=; b=ap9AmZCsYNiP8yH8yF6KAkiQZHZI+v2X5B6pQRBbCtA4tYyi9iUSEENP1owoXFw2nYje+a WmglODEBR9remE/wnT+EOzrjQiZi45rGbvSMcyxxvL41kti3b7YeBfH0URocy76bjKCxo6 sYd1oKhylLgLMk+DR1Q+S5hGcnvBTEM= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="Im/CuRNv"; spf=pass (imf24.hostedemail.com: domain of yuzhao@google.com designates 209.85.217.43 as permitted sender) smtp.mailfrom=yuzhao@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673824461; a=rsa-sha256; cv=none; b=Xout6ctcMA9Mg30IfYGVVoFXLdepMb75JUb6cyEgCpawoUR+O5neDOEHJpioicB+2MSakO +ln/4zWgWK5RgyIb88Flqte0i44j0h10iGU3DbXLLAoX/xLp0jwH6u4+7Adqqb92XRFsOU 0YC0m+2MpzcVK/tLtQ6Vs4jFjFC6Tyw= Received: by mail-vs1-f43.google.com with SMTP id i188so27470322vsi.8 for ; Sun, 15 Jan 2023 15:14:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=86dZ2QP+sHr0Jg65uUt9BrhUPIsdfEcbXYkErF8fpe8=; b=Im/CuRNvt2HbuN0YhQaoN3HBTTH8A9o3TzZnpRoJtWLjbUXAdbWA3NAongNzK79PcQ Qxnh3WpYwmU5TtOSHWPz/Oeme1I2UYZgMUIiWfQkgygOkRsnmwzw7X81+CaVEdCTjCt3 WONAceBrl3RKn2IjP5jU+1x7657QgRrlekQb+0y7IxVMRXCxva1JSK82jze7W4sTKL/h UlsoAl14g/RD8sFGVXcpDkcdeWj3irHzPoJrLjwoNanov4ou6A7LGeqsnzCKp8Zm24qv 6wHprB12URJWT+V9mQD33Z3WB/UUrYf93Ij0FH/KuPf66U1yFrPoLu8qA5YUuhcc+yaC 7F0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=86dZ2QP+sHr0Jg65uUt9BrhUPIsdfEcbXYkErF8fpe8=; b=iXFRsgUS+PigEkJ0TYC/Hj2/a6wPTiTygT+cKpir+c/yzqwqhNdiIwnzcC+4dzpk/7 jVlen9fCEt5JK3nOka5UQje3Q/5fRZrKmCCSMduO13da4h6SFGThQEDlrJdXyFAQ00h3 mH7PNtyPqSUInQdzn7lTwzqF5xXrcjeWwUkORcOiqANltB05HCjJWbBSKRIutIxpP/jt ttOMoWK95aQzkXfHbxMR6Q6nTAW7Eo9ZWh8X+scN7x39PU2dIjLyJUstIVjaYDGZYOJP P39VLeGXlcVLnLjvkSRVHqUlatb3xF+RBtMPk+J96vLJ0kl9F50Q1pcG9yiccUlQokim JnHA== X-Gm-Message-State: AFqh2koQENRpii73IK0z4irvZYC0ygdXJws0uyfdlQE1IDMt/ygWieps rIfblFzhINrD3I3Nx6KYLCQ0I37zL2jW6jfxAFtlPSlJaWBPgQ== X-Google-Smtp-Source: AMrXdXvr9+3nCniBtFEFOOdagtwnvEr8KGuwOTzqhvMxyHOBldSHehd5Tr5QzMJnq4k+mEDLBKbmu317q91j3p2T6JQ= X-Received: by 2002:a67:ecd4:0:b0:3ce:8835:de03 with SMTP id i20-20020a67ecd4000000b003ce8835de03mr7285245vsp.50.1673824460397; Sun, 15 Jan 2023 15:14:20 -0800 (PST) MIME-Version: 1.0 References: <20230115133330.28420-1-msizanoen@qtmlabs.xyz> <20230115134651.30028-1-msizanoen@qtmlabs.xyz> In-Reply-To: <20230115134651.30028-1-msizanoen@qtmlabs.xyz> From: Yu Zhao Date: Sun, 15 Jan 2023 16:13:44 -0700 Message-ID: Subject: Re: [PATCH v2] mm: do not try to migrate lru_gen if it's not associated with a memcg To: msizanoen1 Cc: Andrew Morton , stable@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: 45cesewymb6barrpjyuuz8af5d3uaush X-Rspam-User: X-Rspamd-Queue-Id: 5558818000E X-Rspamd-Server: rspam06 X-HE-Tag: 1673824461-714476 X-HE-Meta: U2FsdGVkX1/nvejJDRtBv0qc9KGeKECcjxYEEnGXrRil+fNthGsXUlxueNCJtA3H8ZV6lqqMqjWfneHPRfDpeP5ErIQpyHE5s03CSJSNnD1JJb7rGpIh3gXvIZVrB+IWAV2Id50ElTMANQLcn4YrLeFbIWj/xhSpUA6khRh1bpKA6XLyPLNJS6AojOJSsFGpLyk8FufOquvdTTKV3xSIUCR1nqP1u/078ys/nQRQlPcTvV63m8GAFmeYYhTnoHEFk5N4Uo11fw7odqva/l31KiTA35NocOIyiS159xvTGjElJFriXMkgP/azuNgrJ93K++jEYvdDiwF6JL39RCmIQs7Cd3faxj89BimkSjPLyu9xZ1BI5BZzAfFxwCJkjstW0mhHSX0sLiUkPhNo08QpSJ3lswlPpxg57Mi7cJhxjFFKQTQ3Gx60J8ft23fbXJvHYIidIFitjFFR1ztJJLfRMt4ZO6EzhldGaNlTMA5Gwe3iuajmo370fMD1lHP2wH6HA5MEJmPqkLdeawMaB50g7g+lEIk2jvxKTAqO0i30tR+6mG/191Sp7e8AJQyktW0p3OFxA0rMgDj8d6rskPZsgEG7dvlZLwMZS9o0eTK3QanHj9JJEijJC7bWRGTfaZrl7Sh059Jk6VAGN21ksPSxIwpZ5PsUgDZkiFJZtm2QrwsAl8sTHxK0IPgW3qdcglHP63f2eCrgWJSAt8JL7ww/BXxboZbJNyFVmaOUigzyb8lFx3r8dyqg2J8g+LA8vvoPrpD5R4zXYlfnsDnMEz4jkj2AGCx8ASwyOhTGoR83tLZ3xico2cTXeE82dnw8N3pVQ+GhzR4fmDhm7mZXAUItoa6lUdgXOuxxnxxBEXbhEbrmeBk6OmucLmOre2222PQaXgI/+RgA5cEolsbvglK4scVY274cASBHYBEhxlCa8iITVf2wEiO5+BbN92g9XhC2QqTFSnO/R6iPRh6OeBu p21J4cWR Ppc4tXZYeAn/9dK+EMPdzY9hRK4XAoH1MsvoA2qneNrdaNnkJkNKciGDy7URwTRExppD4OFVPld8BgaY0TBuI2Ei3h8nm+Z0iYl37MQ6n+btgkhcZqa8VDxJt7vq/jQeNv+HPx95h0LcOd9s= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Sun, Jan 15, 2023 at 6:47 AM msizanoen1 wrote: > > In some cases, memory cgroup migration can be initiated by userspace > right after a process was created and right before `lru_gen_add_mm()` is > called (e.g. by some program watching a cgroup and moving away any > processes it detects[1]), which results in the following sequence of > WARNs followed by an Oops as the kernel attempts to perform a > `lru_gen_add_mm()` twice on the same `mm`: ... > Fix this by simply leaving the lru_gen alone if it has not been > associated with a memcg yet, as it should eventually be assigned to the > right cgroup anyway. > > [1]: https://gitlab.freedesktop.org/benzea/uresourced/-/blob/master/cgroupify/cgroupify.c > > v2: > Added stable cc tags > > Signed-off-by: N/A (patch should not be copyrightable) > Cc: stable@vger.kernel.org Thanks for the fix. Cc'ing stable is the right thing to do. The commit message and the comment styles could be easily adjusted to align with the guidelines. I don't think the N/A is acceptible though. I fully respect it if you wish to remain anonymous -- I can send a similar fix crediting you as the "anonymous user " who reported this bug. A bit of background on how I broke it: an old version I have on 4.15 calls lru_gen_add_mm() before cgroup_post_fork(), which excludes cgroup migrations by cgroup_threadgroup_rwsem. When I rebased it, I made lru_gen_add_mm() depend on task_lock for the synchronization with cgroup migrations -- the decoupling seemed (still seems) to make it less complicated -- but this is not safe unless we have the check below. > --- > mm/vmscan.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/mm/vmscan.c b/mm/vmscan.c > index bd6637fcd8f9..0cac40e7484c 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -3323,13 +3323,19 @@ void lru_gen_migrate_mm(struct mm_struct *mm) > if (mem_cgroup_disabled()) > return; > > + /* This could happen if cgroup migration is invoked before the process > + * lru_gen is associated with a memcg (e.g. during process creation). > + * Simply ignore it in this case as the lru_gen will get assigned the > + * right cgroup later. */ > + if (!mm->lru_gen.memcg) > + return; > + > rcu_read_lock(); > memcg = mem_cgroup_from_task(task); > rcu_read_unlock(); > if (memcg == mm->lru_gen.memcg) > return; > > - VM_WARN_ON_ONCE(!mm->lru_gen.memcg); > VM_WARN_ON_ONCE(list_empty(&mm->lru_gen.list)); > > lru_gen_del_mm(mm);