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 X-Spam-Level: X-Spam-Status: No, score=-11.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 929C4C2D0A3 for ; Fri, 6 Nov 2020 15:10:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CC4FC22227 for ; Fri, 6 Nov 2020 15:10:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="CfjTEv+J" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CC4FC22227 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D29AC6B005C; Fri, 6 Nov 2020 10:10:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CD99D6B005D; Fri, 6 Nov 2020 10:10:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BEFD06B0068; Fri, 6 Nov 2020 10:10:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0030.hostedemail.com [216.40.44.30]) by kanga.kvack.org (Postfix) with ESMTP id 956FA6B005C for ; Fri, 6 Nov 2020 10:10:13 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 2C990181AEF1A for ; Fri, 6 Nov 2020 15:10:13 +0000 (UTC) X-FDA: 77454329106.12.girl20_0d01ce5272d3 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id F274118054902 for ; Fri, 6 Nov 2020 15:10:12 +0000 (UTC) X-HE-Tag: girl20_0d01ce5272d3 X-Filterd-Recvd-Size: 6692 Received: from mail-lf1-f66.google.com (mail-lf1-f66.google.com [209.85.167.66]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Fri, 6 Nov 2020 15:10:12 +0000 (UTC) Received: by mail-lf1-f66.google.com with SMTP id s30so2400081lfc.4 for ; Fri, 06 Nov 2020 07:10:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=J875vJy4G6JRz4RHdTS0OV7v0tPgG3iBUds7VS16zmE=; b=CfjTEv+JuiJbqP3tNIDaqkmsOq4d/P2UJ3l2SP5rP3+619BmCSAfpFZjxtSyqXgGyo JA516SjkbzjGilEMWaHbWskuDT9po/r+gpxXj4h6rmOJnU43+qEgP3j4Uufzu3OIdQlO e1zfOBsXkNVdYo+Ke4+mmkpASCd+AJqpNWLes3+lqYvRqm8K7grgwgpSV21Q/JrEBo+m 2oiZFZE4uAk06S2nINjhrDlceGJVuOxzd9LNKS4RlIBqBHV+/dXY2QceY4U3DZ6Uk5xr LHsentyuwZxHQ7cAiqMIW3ZVLco6qr3Qe0hcu5t7VH3jrckoysHcDsJLe6AoZk10pz6E +/4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=J875vJy4G6JRz4RHdTS0OV7v0tPgG3iBUds7VS16zmE=; b=LbQWCNoizux2r8cZ7olltvxr6pLROFVG3dQB/FxJvZGmPMMP0FiUJA82bEEc2beKRx pGzoer5aOAtcrSgJiOsWb5cSMwJA9h8/2YTekV7sYPRkm1gHt3SnvMkMQlUZ4PdUBA9f mZYizPyd6FzFtAnc2lmrim+P6TmD8AqvvMGfBIyDGgWCNZBc4CMUS9ZxI7fogBznYMlu 9zSvb4eAKTe1/aDaXFoB+3DFyIoWY28qbJA4wBnsoN9aoQqoFltyFlJmv4EVnEfPFbw0 Bn4OrH8+kvTg4N5lEj/mJhWCo8yPXk/SiwbL4HVPZYeOdLdKx93sTdKsgM5fXKMOwvTx GrPg== X-Gm-Message-State: AOAM531ObGmBVrLmPQ66he9YBupJmusHncpQYLpANmgEchNHsEn3rf3z 0BdoaQwkrSyJDKAZJ5m0qrtRhccInZk6oH1vROK8Lw== X-Google-Smtp-Source: ABdhPJyaeOu53rdnZPr4ni399H9U3vOZ12MXF2gx2gxY/O2mk7BoRTDLUdbJDE26YRcI8seTjqgYhARUGTByNKp95ZQ= X-Received: by 2002:a19:8741:: with SMTP id j62mr1018286lfd.449.1604675410452; Fri, 06 Nov 2020 07:10:10 -0800 (PST) MIME-Version: 1.0 References: <20201104231928.1494083-1-shakeelb@google.com> In-Reply-To: From: Shakeel Butt Date: Fri, 6 Nov 2020 07:09:58 -0800 Message-ID: Subject: Re: [PATCH] mm/rmap: always do TTU_IGNORE_ACCESS To: Hugh Dickins Cc: Jerome Glisse , Johannes Weiner , Andrew Morton , Vlastimil Babka , Michal Hocko , Linux MM , LKML , Balbir Singh Content-Type: text/plain; charset="UTF-8" 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 Thu, Nov 5, 2020 at 7:00 PM Hugh Dickins wrote: > > I don't know why this was addressed to me in particular (easy to imagine > I've made a mod at some time that bears on this, but I haven't found it); > but have spent longer considering the patch than I should have done - > apologies to everyone else I should be replying to. > I really appreciate your insights and historical anecdotes. I always learn something new. > On Wed, 4 Nov 2020, Shakeel Butt wrote: > > > Since the commit 369ea8242c0f ("mm/rmap: update to new mmu_notifier > > semantic v2"), the code to check the secondary MMU's page table access > > bit is broken for !(TTU_IGNORE_ACCESS) because the page is unmapped from > > the secondary MMU's page table before the check. More specifically for > > those secondary MMUs which unmap the memory in > > mmu_notifier_invalidate_range_start() like kvm. > > Well, "broken" seems a bit unfair to 369ea8242c0f. It put a warning > mmu_notifier_invalidate_range_start() at the beginning, and matching > mmu_notifier_invalidate_range_end() at the end of try_to_unmap_one(); > with its mmu_notifier_invalidate_range() exactly where the > mmu_notifier_invalidate_page() was before (I think the story gets > more complicated later). Yes, if notifiee takes invalidate_range_start() > as signal to invalidate all their own range, then that will sometimes > cause them unnecessary invalidations. > > Not just for !TTU_IGNORE_ACCESS: there's also the !TTU_IGNORE_MLOCK > case meeting a VM_LOCKED vma and setting PageMlocked where that had > been missed earlier (and page_check_references() has intentionally but > confusingly marked this case as PAGEREF_RECLAIM, not to reclaim the page, > but to reach the try_to_unmap_one() which will recognize and fix it up - > historically easier to do there than in page_referenced_one()). > > But I think mmu_notifier is a diversion from what needs thinking about. > > > > > However memory reclaim is the only user of !(TTU_IGNORE_ACCESS) or the > > absence of TTU_IGNORE_ACCESS and it explicitly performs the page table > > access check before trying to unmap the page. So, at worst the reclaim > > will miss accesses in a very short window if we remove page table access > > check in unmapping code. > > I agree with you and Johannes that the short race window when the page > might be re-referenced is no issue at all: the functional issue is the > one in your next paragraph. If that's agreed by memcg guys, great, > then this patch is a nice observation and a welcome cleanup. > > > > > There is an unintented consequence of !(TTU_IGNORE_ACCESS) for the memcg > > reclaim. From memcg reclaim the page_referenced() only account the > > accesses from the processes which are in the same memcg of the target > > page but the unmapping code is considering accesses from all the > > processes, so, decreasing the effectiveness of memcg reclaim. > > Are you sure it was unintended? > > Since the dawn of memcg reclaim, it has been the case that a recent > reference in a "foreign" vma has rescued that page from being reclaimed: > now you propose to change that. I expect some workflows will benefit > and others be disadvantaged. I have no objection myself to the change, > but I do think it needs to be better highlighted here, and explicitly > agreed by those more familiar with memcg reclaim. The reason I said unintended was due to bed7161a519a2 ("Memory controller: make page_referenced() cgroup aware"). From the commit message it seems like the intention was to not be influenced by foreign accesses during memcg reclaim but it missed to make try_to_unmap_one() memcg aware. I agree with you that this is a behavior change and we have explicitly agree to not let memcg reclaim be influenced by foreign accesses.