Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp15260991rwb; Mon, 28 Nov 2022 09:32:36 -0800 (PST) X-Google-Smtp-Source: AA0mqf7mUfs1yRF8vZHwoBQhdOFl34OEQ1vGUosL14Fu9lYpaQzRPdg13L02SPQ0LCNJbcnDhYEH X-Received: by 2002:a17:906:1585:b0:7ad:84c7:502d with SMTP id k5-20020a170906158500b007ad84c7502dmr30530451ejd.177.1669656756280; Mon, 28 Nov 2022 09:32:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669656756; cv=none; d=google.com; s=arc-20160816; b=ySssYr8hCqAO2FFAMLLDMtfxyc9fclqBmbSV74Qfi9nPvS/3KjgEngSM+2l8CwAacn CzSyJVzQfSNYmk+kySRhNZ4x2fWJPw9i+gwo87ouRY+f9hvUtAcENrwe2m2XaF7Nl/bU wI+YKnJysx2IP/d7+p1BGYxsE8mnbDrQ5YkiFSNwcpar6e+s3kpV7uu32S4mdqimFlKA 34tw9B9URO7XMcs1OztzG3cdjLbUOABFH0eRGYZQCi344aDsf+UTCxU4a71IrwkZ5Itz zx8350OCpWMyf86g7MTh8rpnrLKmY+lfqZ+OBNIAsC+KRk13xQ0gvxHcyJzqay/xz/MT /yhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=OXdDTBqVegaar+pLWmnzFVWbntmDwb7qj9MvTJ7r5tA=; b=Eo4+IFIUIkDniMTQyw087bELcMS8LtV+Mhb+6WoOHMQ0pB3pqInY3DqkY/bF4QahlR 81nXsY9MqD4XveO3ERprWTTogNYPlTRFZW3VGVJZZQIDKxBcm5dQtOiiKwa3Y1IQTNo1 y3XTCHVS15O1caGVkjIJKzH/poJQnU1mjzLLXmn6afq//Kxy6+Vio+Df80n4RAWZfcHW /0RjuGc2uUSbYsOi7Hx6Avb9yyg+zJLPtoTwD102T8+YsZ8J1FfLFq62S8q8ABuiPida 5P4JmpWNG8SWG/0vw5ClaUpkYyYAEq6YJN5RpAgBeDp2X2Pq7XG6Qy60W09SF2hzyEU+ PymA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=SpduupwX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dn2-20020a17090794c200b007877eb5687csi11059062ejc.249.2022.11.28.09.32.14; Mon, 28 Nov 2022 09:32:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=SpduupwX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232056AbiK1RAA (ORCPT + 84 others); Mon, 28 Nov 2022 12:00:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231968AbiK1Q75 (ORCPT ); Mon, 28 Nov 2022 11:59:57 -0500 Received: from mail-qv1-xf33.google.com (mail-qv1-xf33.google.com [IPv6:2607:f8b0:4864:20::f33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A80E558E for ; Mon, 28 Nov 2022 08:59:54 -0800 (PST) Received: by mail-qv1-xf33.google.com with SMTP id r15so7305204qvm.6 for ; Mon, 28 Nov 2022 08:59:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20210112.gappssmtp.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=OXdDTBqVegaar+pLWmnzFVWbntmDwb7qj9MvTJ7r5tA=; b=SpduupwX9+hgKbJAt1uBrr8GR8cVFBKX0qw5ONERsYzdWfB/N9QQYj9qCTlogNAj9M kEK1FZaNNPnXmtE+uVPtkinRgEpJ1JoknUQoYwGF0Q32h29zIr9jgsAs8IBYPk+9JHOn Su5WwW7J6E51pqICAcNNXMFqDgpDkcudvpSBi+GuH7OKHiHtB7StrdVPvzjyKor5dNKH qSYxxiWRzhj/yNfWFvtLA5Lw0fHWShpuoKz07eFZ+qSags11ZrQ6yOn7HI7EsRUagcth y3wAQAJjBGqBze7yEFUSoIPh0PUs+jQdGn2yb51ZjJ1Qw/2m/kffiVI1MZUrJWniHcRb 5pxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=OXdDTBqVegaar+pLWmnzFVWbntmDwb7qj9MvTJ7r5tA=; b=YwYzD9qsjPmvV+fpoQoGNfKCpV3pUc6APDu2V5Af7XsG++EhEkSwhoam2CUz44xGfY hcXHVyO5T/TAgetEoT9JcnDPPqk9fkjCsnkLc6rU/ExA28AxY2Jkd/+nksC82TcdZbZR oGPwyusL/L/FojyU+1WcSn2d0cLrsd/OF+7aIIyV2VxZU+X1oXi50O94gt9O42vYrtlg jGcskZkcwVDde6b1ov1jj5w9fqz4S7m9AthJmcSb4/mCgg705+TQlcvNBH0DCfAtRKEN U937yGHbBjlBNjjf+7COKlRTIaqDDH9X2mvc9Yp0mmp7mgGaPHwg7e64MqwU5RwLN7g6 q0Aw== X-Gm-Message-State: ANoB5pnLQQkqVBtBhkba0loP+tgx3anJ7oCennLmVC9zUTJQ2HKprIiw 298Px4k5qIZ2YZ2WSx2OMCFIox8emLLKwA== X-Received: by 2002:a05:6214:328f:b0:4c6:82cd:92d1 with SMTP id mu15-20020a056214328f00b004c682cd92d1mr32083981qvb.82.1669654793427; Mon, 28 Nov 2022 08:59:53 -0800 (PST) Received: from localhost (2603-7000-0c01-2716-9175-2920-760a-79fa.res6.spectrum.com. [2603:7000:c01:2716:9175:2920:760a:79fa]) by smtp.gmail.com with ESMTPSA id s23-20020ac85297000000b003a5430ee366sm7141054qtn.60.2022.11.28.08.59.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Nov 2022 08:59:53 -0800 (PST) Date: Mon, 28 Nov 2022 11:59:52 -0500 From: Johannes Weiner To: Hugh Dickins Cc: Andrew Morton , Linus Torvalds , Shakeel Butt , Stephen Rothwell , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm: remove lock_page_memcg() from rmap Message-ID: References: <20221123181838.1373440-1-hannes@cmpxchg.org> <16dd09c-bb6c-6058-2b3-7559b5aefe9@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <16dd09c-bb6c-6058-2b3-7559b5aefe9@google.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 23, 2022 at 10:03:00PM -0800, Hugh Dickins wrote: > On Wed, 23 Nov 2022, Johannes Weiner wrote: > > rmap changes (mapping and unmapping) of a page currently take > > lock_page_memcg() to serialize 1) update of the mapcount and the > > cgroup mapped counter with 2) cgroup moving the page and updating the > > old cgroup and the new cgroup counters based on page_mapped(). > > > > Before b2052564e66d ("mm: memcontrol: continue cache reclaim from > > offlined groups"), we used to reassign all pages that could be found > > on a cgroup's LRU list on deletion - something that rmap didn't > > naturally serialize against. Since that commit, however, the only > > pages that get moved are those mapped into page tables of a task > > that's being migrated. In that case, the pte lock is always held (and > > we know the page is mapped), which keeps rmap changes at bay already. > > > > The additional lock_page_memcg() by rmap is redundant. Remove it. > > > > Signed-off-by: Johannes Weiner > > Thank you, I love it: but with sorrow and shame, NAK to this version. > > I was gearing up to rush in the crash fix at the bottom, when testing > showed that the new VM_WARN_ON_ONCE(!folio_mapped(folio)) actually hits. > > So I've asked Stephen to drop this mm-unstable commit from -next for > tonight, while we think about what more is needed. > > I was disbelieving when I saw the warning, couldn't understand at all. > But a look at get_mctgt_type() shatters my illusion: it's doesn't just > return a page for pte_present(ptent), it goes off looking up swap > cache and page cache; plus I've no idea whether an MC_TARGET_DEVICE > page would appear as folio_mapped() or not. Thanks for catching this. A device_private pte always has a matching mapcount in the fake page it points to, so we should be good here. Those pages migrate back and forth between system and device memory, relying on the migration code's unmap and restore bits. Hence they participate in regular rmap. The swapcache/pagecache bit was a brainfart. We acquire the folio lock in move_account(), which would lock out concurrent faults. If it's not mapped, I don't see how it could become mapped behind our backs. But we do need to be prepared for it to be unmapped. > Does that mean that we just have to reinstate the folio_mapped() checks > in mm/memcontrol.c i.e. revert all mm/memcontrol.c changes from the > commit? Or does it invalidate the whole project to remove > lock_page_memcg() from mm/rmap.c? I think we have to bring back the folio_mapped() conditional and update the comments. But it shouldn't invalidate the whole project. I'll triple check this, however. Thanks