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 E408FCD1296 for ; Mon, 8 Apr 2024 14:23:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 17B1D6B0085; Mon, 8 Apr 2024 10:23:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 104CB6B0087; Mon, 8 Apr 2024 10:23:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EC0086B0088; Mon, 8 Apr 2024 10:23:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id CA0BB6B0085 for ; Mon, 8 Apr 2024 10:23:50 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 578DFA0E2F for ; Mon, 8 Apr 2024 14:23:50 +0000 (UTC) X-FDA: 81986583420.17.C1EFBE5 Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) by imf11.hostedemail.com (Postfix) with ESMTP id 7353440007 for ; Mon, 8 Apr 2024 14:23:47 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=dl0NTvyt; spf=pass (imf11.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.160.180 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712586227; 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=KEVpmUFr/QX1uwVzNDuqt+LyFWtd2iR3AzPxRhcceaY=; b=IIWiEi/m9X56Rs7UBSasMuU+X6KpC3M/eo4TD4jkJ3L7bHgd6jUR17KoniYdmFHSENV5eo 1bYeFHsmQRAgNCRQt3G26LUw8CJsImrRCq8YNfOdy1nHhS+RsCQTzi0wNXrmRsKmPckF1Q lXmCBx/MXgrGyPlmWSpF4IhWMgIB7QE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712586227; a=rsa-sha256; cv=none; b=KCm2PrJqhYLUz84sQvLz2tkOOTW1wnLdmvdtn9c/S6iAPNRHMOJBstQtdk6mygxmPu7jyV CJypSt6HE7tDSnAbEN0xhgSHHFaTXJxZTEYpPjMl+T+AMxkOFPpUrI4/1JUOIIBhkYxC9t HYZGHoobd1Az1mQuamlKVXjrbdzTqLY= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=dl0NTvyt; spf=pass (imf11.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.160.180 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org Received: by mail-qt1-f180.google.com with SMTP id d75a77b69052e-434a76386feso4892851cf.1 for ; Mon, 08 Apr 2024 07:23:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1712586226; x=1713191026; darn=kvack.org; 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=KEVpmUFr/QX1uwVzNDuqt+LyFWtd2iR3AzPxRhcceaY=; b=dl0NTvytN28oq33DI+wohKkVsmeG8fJvsb9UweG/ws8JKdWfSkuxU0Ran3NTNx8B5g 5hjyTmd8MWK/iXLkvgUM/HzrnZRYIF6eSbiFyJES4uMizEY8vUeeeNAlRMYNdn84z72e gqSIU8cWsnhssWR2sZYYTlyZ9o3/2RiF8hXI5C+DAJ7Jy4NuW8/kJPgPyXqNYUEJMmAl i9pRldbB3zFlTyFjYw2Pz3fkpDN2mgHgshD2DzcePuviG3NuZ+Vxwkwjc6sE8UEzi86N /017IVQKJSG9EEs6nW3sKWgVknOYUCMcHG8SUJbMEhRkqQ0r9G4yw1LLyeHu8HmRYkSE dBLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712586226; x=1713191026; 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=KEVpmUFr/QX1uwVzNDuqt+LyFWtd2iR3AzPxRhcceaY=; b=m9en7R+pDVpnDXGL/YHoTlAIxmZEFVW6eWNeJsquw6PrUHdR2N9Ysh9hwqrjXBWjGz xMgRz4EGrRRocXr6diYM5y/S7ppC7XoF8zO3bWqjJ47BqGL8vy5/y8qEE8sj2Aev7fo5 rmvQyJgFYQe+53ix9PweL0sFzRjMo0G3YhRp/LjRgqmBpdW5/pFJUR7h7iUH5BGS2ugC XDw5fBBc8w778zr96UC3TfaKSPAbC6sO1zGGmyLs+leBLBfH0z8OGiAZgndDkg80SjqO XKdvbMpoH2YVB5Y5W/jQal6R0pbQXyg0+DnwNLFBoPsMfSVRM0l309CVX0qo83NkutAN ++Eg== X-Forwarded-Encrypted: i=1; AJvYcCVmNIcKR9MavcHX0lKtHYrUE3pyoZwIuJMnZEJL1fYfDTteXHCYVNsu96/tEa8lw/sLD4U4t324om7DZOQsOfnWKQE= X-Gm-Message-State: AOJu0YzS/jLDjSSSJXUebibN3P+WAOyqerU+L1+PSI4rJw143ReUQ07g cPTsJZZl0lQg+07KvTdviF4vjdEsNfsB/8IdOoLWuM2FORjaZn8bafE+aRTI5eU= X-Google-Smtp-Source: AGHT+IHhi7atJ1Hb/6KDmXmfIEnnCqao5WVXm8HXjj+8zwQJy6VWOp26z68yRrf8ADPs5t31dI2GtQ== X-Received: by 2002:ac8:738f:0:b0:434:7dbe:9549 with SMTP id t15-20020ac8738f000000b004347dbe9549mr4758485qtp.39.1712586226346; Mon, 08 Apr 2024 07:23:46 -0700 (PDT) Received: from localhost ([2620:10d:c091:400::5:3ad2]) by smtp.gmail.com with ESMTPSA id bz7-20020a05622a1e8700b00430a67b3437sm3724002qtb.17.2024.04.08.07.23.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 07:23:45 -0700 (PDT) Date: Mon, 8 Apr 2024 10:23:40 -0400 From: Johannes Weiner To: Vlastimil Babka Cc: Baolin Wang , Andrew Morton , Mel Gorman , Zi Yan , "Huang, Ying" , David Hildenbrand , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 10/10] mm: page_alloc: consolidate free page accounting Message-ID: <20240408142340.GA1057805@cmpxchg.org> References: <20240320180429.678181-1-hannes@cmpxchg.org> <20240320180429.678181-11-hannes@cmpxchg.org> <7b3b7f2e-7109-4e72-b1cf-259cb56f3629@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 7353440007 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: h71xoknir6id3esuidibykdjgtukzsp9 X-HE-Tag: 1712586227-868492 X-HE-Meta: U2FsdGVkX19FhmpnvA8eSZp6h8gfw0OoteC/ZiUY4ChBLG86twsw/HklNwG/vJ0r1WctqG3qwO9bil6dG+daG7iYYRoeDraFQ2fVgRYyENZkoLU+3ZkNEDb10KA+kNhrfw+zdEfZhtBJnh83BgJ09M4BCw1xK3bRYLBTbp5XIjxXrUFNDe5fhVfdS9puM6JALzAJgZbvcZeJe9G3r97Fmxa9sxM19+4+82v6BsHRg0gFu2CfGa/aB1RYOmDrnE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MsoND2b3OOgVVlxTj/nhmSeje+m2dKOL9lerdhn4lvkXHBeC4FdDAwrDE9gR4XqVZhbAywlWs8Iy7lK+LeWIVmCOGIBN25i61z1B/sW6ElFQ/hqXX4TBf9/WQ53kQDuHGevNjL0TkJNgd6caaeoiOwU4wMqTDZzGhmicdzMnMeV3DuNUZqJiO0w== 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: List-Subscribe: List-Unsubscribe: On Mon, Apr 08, 2024 at 09:38:20AM +0200, Vlastimil Babka wrote: > On 4/7/24 12:19 PM, Baolin Wang wrote: > > On 2024/3/21 02:02, Johannes Weiner wrote: > >> > >> + account_freepages(page, zone, 1 << order, migratetype); > >> + > >> while (order < MAX_PAGE_ORDER) { > >> - if (compaction_capture(capc, page, order, migratetype)) { > >> - __mod_zone_freepage_state(zone, -(1 << order), > >> - migratetype); > >> + int buddy_mt = migratetype; > >> + > >> + if (compaction_capture(capc, page, order, migratetype)) > >> return; > >> - } > > > > IIUC, if the released page is captured by compaction, then the > > statistics for free pages should be correspondingly decreased, > > otherwise, there will be a slight regression for my thpcompact benchmark. > > > > thpcompact Percentage Faults Huge > > k6.9-rc2-base base + patch10 + 2 fixes > > Percentage huge-1 78.18 ( 0.00%) 71.92 ( -8.01%) > > Percentage huge-3 86.70 ( 0.00%) 86.07 ( -0.73%) > > Percentage huge-5 90.26 ( 0.00%) 78.02 ( -13.57%) > > Percentage huge-7 92.34 ( 0.00%) 78.67 ( -14.81%) > > Percentage huge-12 91.18 ( 0.00%) 81.04 ( -11.12%) > > Percentage huge-18 89.00 ( 0.00%) 79.57 ( -10.60%) > > Percentage huge-24 90.52 ( 0.00%) 80.07 ( -11.54%) > > Percentage huge-30 94.44 ( 0.00%) 96.28 ( 1.95%) > > Percentage huge-32 93.09 ( 0.00%) 99.39 ( 6.77%) > > > > I add below fix based on your fix 2, then the thpcompact Percentage > > looks good. How do you think for the fix? > > Yeah another well spotted, thanks. "slight regression" is an understatement, > this affects not just a "statistics" but very important counter > NR_FREE_PAGES which IIUC would eventually become larger than reality, make > the watermark checks false positive and result in depleted reserves etc etc. > Actually wondering why we're not seeing -next failures already (or maybe I > just haven't noticed). Good catch indeed. Trying to understand why I didn't notice this during testing, and I think it's because I had order-10 pageblocks in my config. There is this in compaction_capture(): if (order < pageblock_order && migratetype == MIGRATE_MOVABLE) return false; Most compaction is for order-9 THPs on movable blocks, so I didn't get much capturing in practice in order for that leak to be noticable. In earlier versions of the patches I had more aggressive capturing, but also did the accounting in add_page_to/del_page_from_freelist(), so capturing only steals what's already accounted to be off list. With the __add/__del and the consolidated account_freepages() optimization, compaction_capture() needs explicit accounting again. > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > > index 8330c5c2de6b..2facf844ef84 100644 > > --- a/mm/page_alloc.c > > +++ b/mm/page_alloc.c > > @@ -805,8 +805,10 @@ static inline void __free_one_page(struct page *page, > > while (order < MAX_PAGE_ORDER) { > > int buddy_mt = migratetype; > > > > - if (compaction_capture(capc, page, order, migratetype)) > > + if (compaction_capture(capc, page, order, migratetype)) { > > + account_freepages(zone, -(1 << order), migratetype); > > return; > > + } > > > > buddy = find_buddy_page_pfn(page, pfn, order, &buddy_pfn); > > if (!buddy) > > > > With my fix, the THP percentage looks better: > > k6.9-rc2-base base + patch10 + 2 fixes + > > my fix > > Percentage huge-1 78.18 ( 0.00%) 82.83 ( 5.94%) > > Percentage huge-3 86.70 ( 0.00%) 93.47 ( 7.81%) > > Percentage huge-5 90.26 ( 0.00%) 94.73 ( 4.95%) > > Percentage huge-7 92.34 ( 0.00%) 95.22 ( 3.12%) > > Percentage huge-12 91.18 ( 0.00%) 92.40 ( 1.34%) > > Percentage huge-18 89.00 ( 0.00%) 85.39 ( -4.06%) > > Percentage huge-24 90.52 ( 0.00%) 94.70 ( 4.61%) > > Percentage huge-30 94.44 ( 0.00%) 97.00 ( 2.71%) > > Percentage huge-32 93.09 ( 0.00%) 92.87 ( -0.24%) Acked-by: Johannes Weiner With fixed indentation: diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 70f82635f650..96815e3c22f2 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -805,8 +805,10 @@ static inline void __free_one_page(struct page *page, while (order < MAX_PAGE_ORDER) { int buddy_mt = migratetype; - if (compaction_capture(capc, page, order, migratetype)) + if (compaction_capture(capc, page, order, migratetype)) { + account_freepages(zone, -(1 << order), migratetype); return; + } buddy = find_buddy_page_pfn(page, pfn, order, &buddy_pfn); if (!buddy)