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 A4AD0D0BB6C for ; Thu, 24 Oct 2024 08:16:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 208FE6B0088; Thu, 24 Oct 2024 04:16:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1B9F26B008A; Thu, 24 Oct 2024 04:16:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 032346B0092; Thu, 24 Oct 2024 04:16:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id D8C1F6B0088 for ; Thu, 24 Oct 2024 04:16:17 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 79F591C6DC3 for ; Thu, 24 Oct 2024 08:15:56 +0000 (UTC) X-FDA: 82707787512.01.5EEA68A Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf21.hostedemail.com (Postfix) with ESMTP id 1F7481C000F for ; Thu, 24 Oct 2024 08:15:39 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=OBubRTSL; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="QfFMJNI/"; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=OBubRTSL; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="QfFMJNI/"; dmarc=none; spf=pass (imf21.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729757723; a=rsa-sha256; cv=none; b=tk9THjvyjREni7mGqp/RYSJO2T5wxO4CtjzW1O6qYN3fK7TmfB4T89sdQP7dGUndp8tXFS HefytrAldZE9iut4/XAmIuw995dsnxORjvniAumwnb/lqV5mw6gIDdc27CHWduRe/BSB/d SY7dsIYYvIh7L8z4e8pOtMXyiCVZGP0= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=OBubRTSL; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="QfFMJNI/"; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=OBubRTSL; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="QfFMJNI/"; dmarc=none; spf=pass (imf21.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729757723; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=PUdyD45o51oSv9e/roIlQ1/uAhabhz3IoBa7KyPYKD4=; b=PTiVAFBQN/4tudy2uDg42yJDLd0z1q7WhqIUCl7CPlgOFnlIsrkmZxpBugyCMzpk75gdpE LVREiHsB4FJMmNvaPdAzaLacUAf7RjG2gm/vJlcwxB5xNLpqLQuKyQYo1sv5rPy/GWugPg u4oHdjQbtlTPshdBHYfXEZp6+zMT1qM= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 3F5F11FB7F; Thu, 24 Oct 2024 08:16:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1729757773; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=PUdyD45o51oSv9e/roIlQ1/uAhabhz3IoBa7KyPYKD4=; b=OBubRTSLGYYlVzpN7006ePYeCVtBGuGdJzoDNFmWMsojvupyN8gKAWRnz1I2b92dvQiGZx ISlgdLuKGl44++buPKpvfahJj88fOk7AnWr6dWWKMArLa+TMkyYIQWRTXhqYpR9bBi2IxU XFZoHIZ4QdwbU20wkmnUo16owNDGIfc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1729757773; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=PUdyD45o51oSv9e/roIlQ1/uAhabhz3IoBa7KyPYKD4=; b=QfFMJNI/89VQKpVRvQudPPH7n14UWsG4ZzfLGOmqWo5Cw19EmvxdsXPkVBayLNVunYqs6F ix2NauhQWr6wEvAQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1729757773; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=PUdyD45o51oSv9e/roIlQ1/uAhabhz3IoBa7KyPYKD4=; b=OBubRTSLGYYlVzpN7006ePYeCVtBGuGdJzoDNFmWMsojvupyN8gKAWRnz1I2b92dvQiGZx ISlgdLuKGl44++buPKpvfahJj88fOk7AnWr6dWWKMArLa+TMkyYIQWRTXhqYpR9bBi2IxU XFZoHIZ4QdwbU20wkmnUo16owNDGIfc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1729757773; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=PUdyD45o51oSv9e/roIlQ1/uAhabhz3IoBa7KyPYKD4=; b=QfFMJNI/89VQKpVRvQudPPH7n14UWsG4ZzfLGOmqWo5Cw19EmvxdsXPkVBayLNVunYqs6F ix2NauhQWr6wEvAQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 28D66136F5; Thu, 24 Oct 2024 08:16:13 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id /f2XCU0CGmfcMgAAD6G6ig (envelope-from ); Thu, 24 Oct 2024 08:16:13 +0000 Message-ID: Date: Thu, 24 Oct 2024 10:16:12 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH mm-unstable v1] mm/page_alloc: try not to overestimate free highatomic To: Yu Zhao , Mel Gorman Cc: Michal Hocko , Andrew Morton , David Rientjes , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Link Lin , Matt Fleming References: <20241020051315.356103-1-yuzhao@google.com> <82e6d623-bbf3-4dd8-af32-fdfc120fc759@suse.cz> <97ccf48e-f30c-4abd-b8ff-2b5310a8b60f@suse.cz> Content-Language: en-US From: Vlastimil Babka Autocrypt: addr=vbabka@suse.cz; keydata= xsFNBFZdmxYBEADsw/SiUSjB0dM+vSh95UkgcHjzEVBlby/Fg+g42O7LAEkC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eX64HCyyAH0s6sOCyGF5/p eIhrOn24oBf67KtdAN3H9JoFNUVTYJc1VJU3R1JtVdgwEdr+NEciEfYl0O19VpLE/PZxP4wX PWnhf5WjdoNI1Xec+RcJ5p/pSel0jnvBX8L2cmniYnmI883NhtGZsEWj++wyKiS4NranDFlA HdDM3b4lUth1pTtABKQ1YuTvehj7EfoWD3bv9kuGZGPrAeFNiHPdOT7DaXKeHpW9homgtBxj 8aX/UkSvEGJKUEbFL9cVa5tzyialGkSiZJNkWgeHe+jEcfRT6pJZOJidSCdzvJpbdJmm+eED w9XOLH1IIWh7RURU7G1iOfEfmImFeC3cbbS73LQEFGe1urxvIH5K/7vX+FkNcr9ujwWuPE9b 1C2o4i/yZPLXIVy387EjA6GZMqvQUFuSTs/GeBcv0NjIQi8867H3uLjz+mQy63fAitsDwLmR EP+ylKVEKb0Q2A== In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Action: no action X-Rspam-User: X-Rspamd-Queue-Id: 1F7481C000F X-Rspamd-Server: rspam01 X-Stat-Signature: qbyr1mfosbak9g7jtgpc3de74777dj7m X-HE-Tag: 1729757739-927166 X-HE-Meta: U2FsdGVkX18SaYrMZ+7Iox8TveemG0OP4kbS9nqWavAU+eCaLZuweG9d9sVDqvdou0/FDIIaRcdKnLTGdyLY3Ol8AXVOdSkSTU6J18kjYYyaxcUTGIc0NBJx7gCAtpurn5dwWfMAGSetnZSDnQMg4U2FJKMltP/vH2o04V29ndb20lC3ozgWE3kFgztquy3WP7vRt0VEErKLujmVygbk20EZQsjyAh2s6wp3wbnmlX250wpSc8KiNDCyMvY6L6MRjOwXtGPc+9Xbl6+3CeuP0DFaMvnP2l6N2fZA3Ap8pBTHDFSyt2o8Bpp2hKSluyvRGdDy5hFA63I8QL5MnsF8QQgnC0ym7cWuRE8e+1GnkDL+NwOetvQJ8cxsaxxCoJF80NqsvPilgLkbSmfkWHUlpEi/54FIrkuzaOTiWeTyEbJFRnlWuv9g3msCjwN3ZqQUIXo3OT9U3WMGDuHQ7HeOA8RhQy1oiUPEcR6RhQmGHZulWN1uuzMdy9izK1UeOjuJfbW0rhPxGHAmvLntFjDXqOwiwoXVX7thvgaps21ZGc8ku+LuV85iCfWM491p3uqJNu2pI3JJ/QFTCYY4c+9xOTmv/DouyQh/whnl67ygLkOxnh+WR778Es38yXKKSI+/tlWVzi1PvAAXOZBZ+0jzCYwmQKSDtDhKsmPHVmmm8AZWXJT6wL2p1j7GRerj2uDL0TuynJvUsQbpkDMx+s2z0wgE0lqQmn4dREUeV7A5w1GV2uTh4kChEmrNgKmnZPpf8sk4BExoWRzy9f9JPn1AiLfF8dxCR9vlU4Yz/liUyf+RedhUC8NxHOjvHlAq7odqMAj9UBaWzFG4RcRuUhoC/znu8LDmDyntFOsAmjWPiVgcNxKCJUXA6ZbBtqYBvly8gJdoy9qoLyKmQeEcGu/P+KDweYL5H8R58VtUiODirOGmF6X86vxW1kC2k8Gl6TctbskRe4apneoMGECN+1n xnlA4kgZ UwVxjMDtrTKLkPBHJap1k3hqbd9Xz3GlCx6oZr3B+9hEAA3tl4zdS20CZS9SQXdWM3yOTIKwZFlMGvBScjKb+PfOFoWHpVSatZVXaH/sXTcKLx8iZJVGB7bU64myfSe9tr/GhG8Bwk2++/+2KBY8dntoMZ4DEDl5EmUxETcoh2HEHf3T4j0qcQo0pAPniuD8/JW8V3QkWuUFohGzV8I4DgckLiuBDtj69QpGBVMVWwMMxaLD2fL2ImafWyJkbCT0i+NOzlcVl+FJSbd5hya6as2Zr92GpWsJI9jX+PHFec1VXXRcuw3CuJM5oM7k/X4rn5PlVeTf5Ld4E3ZloQMmdbMvYnJjB0miAsDu8yERiqL5P1+U= 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 10/24/24 06:35, Yu Zhao wrote: > On Wed, Oct 23, 2024 at 1:35 AM Vlastimil Babka wrote: >> >> On 10/23/24 08:36, Yu Zhao wrote: >> > On Tue, Oct 22, 2024 at 4:53 AM Vlastimil Babka wrote: >> >> >> >> +Cc Mel and Matt >> >> >> >> On 10/21/24 19:25, Michal Hocko wrote: >> >> >> >> Hm I don't think it's completely WAI. The intention is that we should be >> >> able to unreserve the highatomic pageblocks before going OOM, and there >> >> seems to be an unintended corner case that if the pageblocks are fully >> >> exhausted, they are not reachable for unreserving. >> > >> > I still think unreserving should only apply to highatomic PBs that >> > contain free pages. Otherwise, it seems to me that it'd be >> > self-defecting because: >> > 1. Unreserving fully used hightatomic PBs can't fulfill the alloc >> > demand immediately. >> >> I thought the alloc demand is only blocked on the pessimistic watermark >> calculation. Usable free pages exist, but the allocation is not allowed to >> use them. > > I think we are talking about two different problems here: > 1. The estimation problem. > 2. The unreserving policy problem. > > What you said here is correct w.r.t. the first problem, and I was > talking about the second problem. OK but the problem with unreserving currently makes the problem of estimation worse and unfixable. >> > 2. More importantly, it only takes one alloc failure in >> > __alloc_pages_direct_reclaim() to reset nr_reserved_highatomic to 2MB, >> > from as high as 1% of a zone (in this case 1GB). IOW, it makes more >> > sense to me that highatomic only unreserves what it doesn't fully use >> > each time unreserve_highatomic_pageblock() is called, not everything >> > it got (except the last PB). >> >> But if the highatomic pageblocks are already full, we are not really >> removing any actual highatomic reserves just by changing the migratetype and >> decreasing nr_reserved_highatomic? > > If we change the MT, they can be fragmented a lot faster, i.e., from > the next near OOM condition to upon becoming free. Trying to persist > over time is what actually makes those PBs more fragmentation > resistant. If we assume the allocations there have similar sizes and lifetimes, then I guess yeah. >> In fact that would allow the reserves >> grow with some actual free pages in the future. > > Good point. I think I can explain it better along this line. > > If highatomic is under the limit, both your proposal and the current > implementation would try to grow, making not much difference. However, > the current implementation can also reuse previously full PBs when > they become available. So there is a clear winner here: the current > implementation. I'd say it depends on the user of the highatomic blocks (the workload), which way ends up better. > If highatomic has reached the limit, with your proposal, the growth > can only happen after unreserve, and unreserve only happens under > memory pressure. This means it's likely that it tries to grow under > memory pressure, which is more difficult than the condition where > there is plenty of memory. For the current implementation, it doesn't > try to grow, rather, it keeps what it already has, betting those full > PBs becoming available for reuse. So I don't see a clear winner > between trying to grow under memory pressure and betting on becoming > available for reuse. Understood. But also note there are many conditions where the current implementation and my proposal behave the same. If highatomic pageblocks become full and then only one or few pages from each is freed, it suddenly becomes possible to unreserve them due to memory pressure, and there is no reuse for those highatomic allocations anymore. This very different outcome only depends on whether a single page is free for the unreserve to work, but from the efficiency of pageblock reusal you describe above a single page is only a minor difference. My proposal would at least remove the sudden change of behavior when going from a single free page to no free page. >> Hm that assumes we're adding some checks in free fastpath, and for that to >> work also that there will be a freed page in highatomic PC in near enough >> future from the decision we need to unreserve something. Which is not so >> much different from the current assumption we'll find such a free page >> already in the free list immediately. >> >> > To summarize, I think this is an estimation problem, which I would >> > categorize as a lesser problem than accounting problems. But it sounds >> > to me that you think it's a policy problem, i.e., the highatomic >> > unreserving policy is wrong or not properly implemented? >> >> Yeah I'd say not properly implemented, but that sounds like a mechanism, not >> policy problem to me :) > > What about adding a new counter to keep track of the size of free > pages reserved for highatomic? That's doable but not so trivial and means starting to handle the highatomic pageblocks much more carefully, like we do with CMA pageblocks and NR_FREE_CMA_PAGES counter, otherwise we risk drifting the counter unrecoverably. > Mel?