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 3F7A6C8302B for ; Mon, 30 Jun 2025 15:39:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AFE2D6B00E0; Mon, 30 Jun 2025 11:39:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AAECB6B00E3; Mon, 30 Jun 2025 11:39:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 99DE36B00E4; Mon, 30 Jun 2025 11:39:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 84AE46B00E0 for ; Mon, 30 Jun 2025 11:39:39 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id BC126BA668 for ; Mon, 30 Jun 2025 15:39:38 +0000 (UTC) X-FDA: 83612476836.26.018692A Received: from mail-yw1-f177.google.com (mail-yw1-f177.google.com [209.85.128.177]) by imf30.hostedemail.com (Postfix) with ESMTP id DC7438000C for ; Mon, 30 Jun 2025 15:39:36 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=UMDk3wFY; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf30.hostedemail.com: domain of joshua.hahnjy@gmail.com designates 209.85.128.177 as permitted sender) smtp.mailfrom=joshua.hahnjy@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1751297976; a=rsa-sha256; cv=none; b=aErSahaU++Rr1Kqdx7GbYk9UNVefufVbJBSVGCrcbgKHWEsO7PUxqUw7gFvLINOQGaEpCr v8aI/1tWS+i6byeFZZ7ca0BiebCFmIHr7dF15qH8uXriR9zbQkjCQx1eLbm2lKi1T16UPj iANQiHN8+laby47e88xK2w4c1fjD/mM= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=UMDk3wFY; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf30.hostedemail.com: domain of joshua.hahnjy@gmail.com designates 209.85.128.177 as permitted sender) smtp.mailfrom=joshua.hahnjy@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1751297976; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=0be5qLAVyxVsqlJv6V/4Pef2SAWqToJNDc4Rx5m5nkQ=; b=63OE4JFum0mssAePMEclkHCJEnFJ8FWt7/eCuFTjmUu1BufVCgPwG6ag1CCqU1WgXtjGzv 5bxrV9dnR22JvDaFy00e1bJ8/xvr9xQJfVdSK9QDQ/1eDLT3vEGvQLMmu00qsudJrEChgK RxhDizo6rKInmtxjJTUkVm85zkTWyhs= Received: by mail-yw1-f177.google.com with SMTP id 00721157ae682-70f94fe1e40so61100717b3.1 for ; Mon, 30 Jun 2025 08:39:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751297976; x=1751902776; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0be5qLAVyxVsqlJv6V/4Pef2SAWqToJNDc4Rx5m5nkQ=; b=UMDk3wFYCXk53EKu92n6q0fQ4FWLuI75pVni2MyCiwub/TsoOWcYLJc5njmmkmOhJL ru5NlMHj+NQuPF37eimC6rwP4q3LDPt2roRQBvg2Dt2d3Yj5+mYCKBRJVUT8a9MsINng 2XqLYaZ6KYwO9e7Sxktvl4yzpm/hWb4LmiICPXIiSzg+UiqgHR7DDNPgk/NQTW82z0Tn VQIZkU+GUk/a5xfI1XQWO9HQpMcKZOvMfS4w+ecXCcYXl0yxNOohrfmRnzoxpDSKDxGP uZ864EnbP15NC5oteBseHTfYAXJpPWEhtkWnmc+H8p3PUDy2r4t6yEVry0U5gRQ1s0jd /DwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751297976; x=1751902776; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0be5qLAVyxVsqlJv6V/4Pef2SAWqToJNDc4Rx5m5nkQ=; b=lBBx+mvLsyufP5qr2BOVUpe3VHQhVBtz6iGsWaBQ+zs7solwh/uR9FagThzLJHWa2+ iO2GFROvqv2uTscO/OnzQuCH/XJQOPKmEjdEYN3zkX84yLhDw3VyiPQZQ4P9PmoDwm3g oaQiDBv8OVtcvnEqZtCsT1HNmiSzbJ5a82RBWRcIMxeda5hUbo2jnhE34AEna96LJMPk m7zxIr2uWiokjT1GMSrXczG8vPDDnk/8KrKM8eFv9Wso4Kmi/tjSOhhLI3yzsr8p9+9C BRyuG3IqYj9IOAtzSteD/qurKbolThlxiUSAmHQi6mNU1HAGA5e2zLuOS6GbfibD5Zlb Gw4g== X-Forwarded-Encrypted: i=1; AJvYcCXeRdcI7cVZncw2ckUM3ub4OyLAewDbHfbMtagbOpxlg4GHvkQfrKdjOELHOlH7srofItWD8L6BQw==@kvack.org X-Gm-Message-State: AOJu0YyoAxAT5gvpFAOQfgwVi9pke/Sg+6AoCxdlNmluLo+DTdE95Mos NaSQiilYK/Mn1Q1Z2GHl3S9Vhd+Gt2Wl7sRdkv1RkNxJeq1KZQDK458K X-Gm-Gg: ASbGncuKO9gEw+kpziqkak9rlfHXLo+GNdRig0zmRj2BAHSe+lTcytKyQ0+Iq7TTFvK OAWe+xj13I+d2yGY5KirC6JLZs+YKqkRYVVzPyu+WQfBIEOTPVDnDRV7i0zcdjoPSQ4y2dER7f9 IRaSKFW6YZDJRB7MtZYK6rlb1grzbE6DTYkpJ6Ooa/nAGS0fOVJwU9xsV5gIn4gOErWngL52oSq lYgANEEeB37xDnWCZT9p+vRmD90KxQbIsSiYreb/rFMvnxGLL1HOMYU+8ognGJVApcUvuvxfUAd 3dLFqaZwV+U1wnf30EE/HzHiEyEiSz5QlSq2yFbYfK86aRkor0vH1cVgDhS4uA== X-Google-Smtp-Source: AGHT+IHzZeRn7Cp9KHkkJ7sj9fF4rhKTnNt/RZSDFZ/SelLCV5QB17xfO3NFNfYD9wL+NPir0D33OQ== X-Received: by 2002:a05:690c:6b0c:b0:70e:77df:f2f9 with SMTP id 00721157ae682-7163ef1e89fmr130527b3.15.1751297975464; Mon, 30 Jun 2025 08:39:35 -0700 (PDT) Received: from localhost ([2a03:2880:25ff:40::]) by smtp.gmail.com with ESMTPSA id 00721157ae682-71515c04195sm15804927b3.37.2025.06.30.08.39.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 08:39:34 -0700 (PDT) From: Joshua Hahn To: Joshua Hahn Cc: Gregory Price , Andrew Morton , Alistair Popple , Byungchul Park , David Hildenbrand , Matthew Brost , Rakie Kim , Ying Huang , Zi Yan , linux-kernel@vger.kernel.org, linux-mm@kvack.org, kernel-team@meta.com Subject: Re: [PATCH 2/2] mm/mempolicy: Skip extra call to __alloc_pages_bulk in weighted interleave Date: Mon, 30 Jun 2025 08:39:33 -0700 Message-ID: <20250630153933.3942464-1-joshua.hahnjy@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250627161318.1898633-1-joshua.hahnjy@gmail.com> References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: DC7438000C X-Stat-Signature: i3xa76a6ejwzo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ZtDHjEK1b9Wr4z88xJSEYjglZeLfqT/1pfKXBe4ZVeIbe+MhwAQZAaaKd6w148LG7mhFb40GNZlgItNMXnheBPc69jJpv1r+5pq4WiePgFChJh8jEeXCchfg+PvLIpA2V/sahzPdVw5QTt0FNhxNef/qQXgyHgCiXOzHH+nsU1mmX8WPSriOCwTzxhRXI1tkzuCDZ3AiQ6/zM10aQurSmSJBmTA1KRn4Q6zDPYXo0TceDoC75hpaPuq7WZigGMI8WcQhN2467yQqpojN+s+sFh5BYTcGvFhNoTxm7GD8YRK9rhdHdZuqoIdYP+B+WhB++KnkxWOvIev5YsLe1kClidgp6OLhMbel1Kb8jdIea8gf6n3++VcubBFpbuPQD2fCeOalfPGPNmVJFCzMDGCDc/5hxbWu4+m1NV4Lwnp0c8bzbOorImRlWXM0zpiADV+FXuiATcMB9GI9ZeJwTH7GdFmPD8XNCTSWHfWSIgxhjRPO2ReXgehoscVGoNaD/zNmcTGGCdReFDJ4AeVJTq80TKEYrdaN96tqdVAE5SwsXjF94htYi0EE15EIYXs8PyEfG1XwTMwwEjVHPMAS5Yuf113QqR9IWgZ4pmAeR6AaZ3YY5viE0/ueaSKKdpkC1zp2uUzpQDfTl+ANGixT 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 Fri, 27 Jun 2025 09:13:18 -0700 Joshua Hahn wrote: > On Fri, 27 Jun 2025 00:28:33 -0400 Gregory Price wrote: > > Hi Gregory, [...snip...] > > I will say that, at least at the time, I took the core math and > > validated the edge conditions in a separate program. > > > > If you get it wrong in the kernel, you'd either fail to allocate - or more > > likely just get the wrong distribution of pages. The latter is > > non-obvious unless you go looking for it, so it might be good to at > > least add this test result in the change log. It's hard to write this > > in LTP or kernel selftest unfortunately. > > I think so too : -( > > One test that I wanted to do while developing this feature was to see if > I could figure out how many pages are really allocated from each node. The > difficulty in doing this (as you pointed out above) is that because there are > other ways that move the round robin forward (without necessarily calling the > bulk alloc function), it's hard to directly attribute the page allocations. > > If this was the only place that we were modifying these values, then a > correctness check would be equivalent to just adding a printk of each node > and how many pages were allocated on it, then adding all the numbers up to > see if it matches the weight ratios in sysfs. > > So I think I will do what you did as well -- I think that performing some > tests, at least on the edge cases in a separate program will help give > some confidence that the code works as intended. I'll also continue to think > about if there are better ways to be testing this instead. Like you suggested, I decided to run a simulation just to see if the number of nodes allocated from each page lined up with the old version, and if the numbers made sense for both cases. I found a few issues with my version of the code: The math is just incorrect when rounds == 0. Let's say there's a 2-node machine with weights [10, 7]. We should start allocating from node0 with 7 remaining pages, and we want to allocate 14 pages. Here's how the new math goes: - First node should allocate 7 pages, let carryover = 7 - Then remaining pages = 14 - 7 = 7 - Allocate rounds * weight + min(weight, delta) + carryover: = 0 * 10 + min(10, 7) + 7 = 7 + 7 = 14 This is incorrect, since we will be allocating all 14 pages from the first node, and the real distribution should be 7 pages from the first node, and 7 pages from the second node. I think this can also lead to some overallocation issues. So there are a few options now: - Change the addition to be: rounds * weight + min(min(weight, delta + carryover), weight) and adjust the remaining math accordingly. But this looks very bad and is not intuitive at all, so I don't like this idea. - This can easily be solved, if instead of figuring out how many pages have to be allocated as we iterate through the nodes, we do one pass and figure out how many pages must be allocated. The problem here is that we re-introduce another loop, which adds to the code complexity and may actually be a performance decrease instead. So again, I don't think this is the best idea. - Skip this patch! This is a small optimization on performance, and I think it simplifies the code, but turns out the original math to do is just much harder without doing two separate calculations. I'll keep this running in the back of my mind to see if I can figure out a way to solve it later... I also think it makes sense to drop the first patch as well, since there's no optimization included with the cleanup. But since it already got a few reviews, maybe it makes to keep that one : -) Anyways, I really appreciate the review Gregory! Maybe I'll have a brekathrough idea on how to correctly do the math here sometime in the future. Have a great day! Joshua Sent using hkml (https://github.com/sjp38/hackermail)