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 8F636C76196 for ; Thu, 6 Apr 2023 20:45:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B77366B0072; Thu, 6 Apr 2023 16:45:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B26A86B0074; Thu, 6 Apr 2023 16:45:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9C7D96B0075; Thu, 6 Apr 2023 16:45:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 8D1DE6B0072 for ; Thu, 6 Apr 2023 16:45:11 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 5D547C11E7 for ; Thu, 6 Apr 2023 20:45:11 +0000 (UTC) X-FDA: 80652146022.01.4FF724C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf04.hostedemail.com (Postfix) with ESMTP id 7A70D4000F for ; Thu, 6 Apr 2023 20:45:08 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SpK1p6RU; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680813909; 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=hlliibCO4sNcXALnaTXV8AY6so6PWo4TfdquJ/Ysd8k=; b=bwEqD6Xa2y1uw+xh9rQNZetQe0XaOJc06MldvJm+eLkdqFlTYtyk4VhA9VT7ldvqHxxHi6 ggl27ZR8gEN/uxHXJ/QvY3S2bpq2oYmuRNSiH1JkB+pkSCeEWek0xhGiUd1TqQFEdis6ax W3Xbf9rL/bEHK7SgBNipwA5hEHQeY1U= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SpK1p6RU; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680813909; a=rsa-sha256; cv=none; b=Bwod1M+Oyru8Mb1IupU+5HO8bw+XY/HsDSVaq7V0zC5thhR3+H35WO8SAkwtTDileRZUBR DM8/0H+3JZreu66SDQdDRLS1GNEcdSGDk0E5UzpsHRBFXns+ON+h/kDzfT1l6fVP3YBYTt TvA7TMl4T44fIg6yJvgIKIbtGLFNmCc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680813907; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=hlliibCO4sNcXALnaTXV8AY6so6PWo4TfdquJ/Ysd8k=; b=SpK1p6RUn617GGWR8yz8Gsocr1ZtymbUoh/+kBEg3M+BHM3LDC+bEVRDTMEKWiP5tL+6bA v+QQnD1bVOQP6WsNkARhIvamkI6guSenwdfIR1H8BnaGSIqiqB/chcqAYHJ/5rXTgHvBWj 3ZTByNDPOCYt75p0yEvGVHFC5vwa0M0= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-628-Chrke39NNl-ocCY1eOJigg-1; Thu, 06 Apr 2023 16:45:06 -0400 X-MC-Unique: Chrke39NNl-ocCY1eOJigg-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-74a25fcda05so12341285a.1 for ; Thu, 06 Apr 2023 13:45:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680813906; x=1683405906; 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=hlliibCO4sNcXALnaTXV8AY6so6PWo4TfdquJ/Ysd8k=; b=XVZ9N+t5J1FnkWBiDMWinNpViXn+8fxjGb1U9NrqOlmLWPXo4BGHIUHcr5bzQPF3Wm +p/eChAQrJTRRi4M8qQGc7vYGL58n9bY2rYQ3tL8O5dS3xbQ4ySdQto+66hpboJpR/FD xwOJ3gTCChr9ym+zvs0Y0hLb14on6Ji9KD5YHQa7lolIVgiDaSnWGPLUdrqsS+z8Gdqm w4svcBjkXJ2Lw8Hwo4N9WvvL4hAXcC82SVRx0mSXklI/YUXhC8wA3QosOblgwGdAXG/4 VAlLjnMPwbyyddWYFNQeGHdwbQ9pllXpY/KXJ9dO6SYfskvtVbN/ZOst0UDDFOneuwoY LQHw== X-Gm-Message-State: AAQBX9eDvrw2JklmiebLoF9t3ANTrUUEkQHest1G+K53BA+aFoxQyXE2 vCzQ2Yn9fmnvQj5jINKXgUuz8nPkLDIEHAliKzL5k+zcccgxswcBznYbV9TUgN0QN4FQQApaM6y DIgTR4zq68sQ= X-Received: by 2002:a05:6214:3018:b0:5af:3a13:202d with SMTP id ke24-20020a056214301800b005af3a13202dmr744172qvb.4.1680813905808; Thu, 06 Apr 2023 13:45:05 -0700 (PDT) X-Google-Smtp-Source: AKy350Y1KJ4vprLWmq2m/5KZ8L4Bi2Rxr9Vn0WKqzah+7elFypEf8sf0YtUFBzrza/xRbtyRgeE1YQ== X-Received: by 2002:a05:6214:3018:b0:5af:3a13:202d with SMTP id ke24-20020a056214301800b005af3a13202dmr744126qvb.4.1680813905342; Thu, 06 Apr 2023 13:45:05 -0700 (PDT) Received: from x1n (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id lz7-20020a0562145c4700b005dd8b9345d9sm137125qvb.113.2023.04.06.13.45.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Apr 2023 13:45:04 -0700 (PDT) Date: Thu, 6 Apr 2023 16:45:02 -0400 From: Peter Xu To: Yosry Ahmed Cc: Andrew Morton , Alexander Viro , "Darrick J. Wong" , Christoph Lameter , David Rientjes , Joonsoo Kim , Vlastimil Babka , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, "Matthew Wilcox (Oracle)" , Miaohe Lin , David Hildenbrand , Johannes Weiner , NeilBrown , Shakeel Butt , Michal Hocko , Yu Zhao , Dave Chinner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v5 2/2] mm: vmscan: refactor reclaim_state helpers Message-ID: References: <20230405185427.1246289-1-yosryahmed@google.com> <20230405185427.1246289-3-yosryahmed@google.com> MIME-Version: 1.0 In-Reply-To: <20230405185427.1246289-3-yosryahmed@google.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Rspamd-Queue-Id: 7A70D4000F X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: z3yz69fzugntmct174bbrcsw1zgdb3r9 X-HE-Tag: 1680813908-116196 X-HE-Meta: U2FsdGVkX19TWdmFaEG5/Lqxd1n2fYrMcitgEEfRwkxaocESzi5LODuLV4k+aF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hE1GSX+JJ7ovnFvM6RQxeTrU2v4JJ0kBQwgKZPjZ+Uk+vvQ3ndS1HyvdHYoJ1LCKZPGd8ve0q4k83PLyf4Gs4tqDfSMLwbGT4PM6myiDXvLtE8F6AmVw3GmgszHPCPd75ZTLV3MBP6np8blxzQRwaSk/z3GL9Og1Wrb2wYrZzdJWOTWqnsMUBfbHJQ3W2vsx4Cf2G4ZMvBRheBT9cpqIeBtPbJLk1u1O6PafgxsHCCsgjTvnuZ0JaaFan7TXIfF6EWgtFrHYqNJeNU0gZLcVNfczbP4ncFr8LSEmVyhW92cj28HIlNCSOMp3DyLydKkdj7BBl9iDvAw897cFUpl/VTN8I1yBImBsS10VSg== 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: Hi, Yosry, On Wed, Apr 05, 2023 at 06:54:27PM +0000, Yosry Ahmed wrote: [...] > diff --git a/mm/vmscan.c b/mm/vmscan.c > index c82bd89f90364..049e39202e6ce 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -188,18 +188,6 @@ struct scan_control { > */ > int vm_swappiness = 60; > > -static void set_task_reclaim_state(struct task_struct *task, > - struct reclaim_state *rs) > -{ > - /* Check for an overwrite */ > - WARN_ON_ONCE(rs && task->reclaim_state); > - > - /* Check for the nulling of an already-nulled member */ > - WARN_ON_ONCE(!rs && !task->reclaim_state); > - > - task->reclaim_state = rs; > -} > - > LIST_HEAD(shrinker_list); > DECLARE_RWSEM(shrinker_rwsem); > > @@ -511,6 +499,59 @@ static bool writeback_throttling_sane(struct scan_control *sc) > } > #endif > > +static void set_task_reclaim_state(struct task_struct *task, > + struct reclaim_state *rs) > +{ > + /* Check for an overwrite */ > + WARN_ON_ONCE(rs && task->reclaim_state); > + > + /* Check for the nulling of an already-nulled member */ > + WARN_ON_ONCE(!rs && !task->reclaim_state); > + > + task->reclaim_state = rs; > +} Nit: I just think such movement not necessary while it loses the "git blame" information easily. Instead of moving this here without major benefit, why not just define flush_reclaim_state() right after previous set_task_reclaim_state()? > + > +/* > + * flush_reclaim_state(): add pages reclaimed outside of LRU-based reclaim to > + * scan_control->nr_reclaimed. > + */ > +static void flush_reclaim_state(struct scan_control *sc, > + struct reclaim_state *rs) > +{ > + /* > + * Currently, reclaim_state->reclaimed includes three types of pages > + * freed outside of vmscan: > + * (1) Slab pages. > + * (2) Clean file pages from pruned inodes. > + * (3) XFS freed buffer pages. > + * > + * For all of these cases, we have no way of finding out whether these > + * pages were related to the memcg under reclaim. For example, a freed > + * slab page could have had only a single object charged to the memcg > + * under reclaim. Also, populated inodes are not on shrinker LRUs > + * anymore except on highmem systems. > + * > + * Instead of over-reporting the reclaimed pages in a memcg reclaim, > + * only count such pages in global reclaim. This prevents unnecessary > + * retries during memcg charging and false positive from proactive > + * reclaim (memory.reclaim). > + * > + * For uncommon cases were the freed pages were actually significantly > + * charged to the memcg under reclaim, and we end up under-reporting, it > + * should be fine. The freed pages will be uncharged anyway, even if > + * they are not reported properly, and we will be able to make forward > + * progress in charging (which is usually in a retry loop). > + * > + * We can go one step further, and report the uncharged objcg pages in > + * memcg reclaim, to make reporting more accurate and reduce > + * under-reporting, but it's probably not worth the complexity for now. > + */ > + if (rs && global_reclaim(sc)) { > + sc->nr_reclaimed += rs->reclaimed; > + rs->reclaimed = 0; > + } > +} > + > static long xchg_nr_deferred(struct shrinker *shrinker, > struct shrink_control *sc) > { > @@ -5346,10 +5387,7 @@ static int shrink_one(struct lruvec *lruvec, struct scan_control *sc) > vmpressure(sc->gfp_mask, memcg, false, sc->nr_scanned - scanned, > sc->nr_reclaimed - reclaimed); > > - if (global_reclaim(sc)) { > - sc->nr_reclaimed += current->reclaim_state->reclaimed_slab; > - current->reclaim_state->reclaimed_slab = 0; > - } > + flush_reclaim_state(sc, current->reclaim_state); > > return success ? MEMCG_LRU_YOUNG : 0; > } > @@ -6474,10 +6512,7 @@ static void shrink_node(pg_data_t *pgdat, struct scan_control *sc) > > shrink_node_memcgs(pgdat, sc); > > - if (reclaim_state && global_reclaim(sc)) { > - sc->nr_reclaimed += reclaim_state->reclaimed_slab; > - reclaim_state->reclaimed_slab = 0; > - } > + flush_reclaim_state(sc, reclaim_state); IIUC reclaim_state here still points to current->reclaim_state. Could it change at all? Is it cleaner to make flush_reclaim_state() taking "sc" only if it always references current->reclaim_state? > > /* Record the subtree's reclaim efficiency */ > if (!sc->proactive) > -- > 2.40.0.348.gf938b09366-goog > -- Peter Xu