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 5F897C636D3 for ; Wed, 1 Feb 2023 23:48:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BD98A6B0071; Wed, 1 Feb 2023 18:48:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B88D66B0072; Wed, 1 Feb 2023 18:48:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A509D6B0078; Wed, 1 Feb 2023 18:48:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 93F216B0071 for ; Wed, 1 Feb 2023 18:48:04 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 6C30FA895B for ; Wed, 1 Feb 2023 23:48:04 +0000 (UTC) X-FDA: 80420363688.04.14C6C4F Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by imf22.hostedemail.com (Postfix) with ESMTP id 90C59C001D for ; Wed, 1 Feb 2023 23:48:02 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=IAPv2JXk; spf=pass (imf22.hostedemail.com: domain of minchan.kim@gmail.com designates 209.85.216.42 as permitted sender) smtp.mailfrom=minchan.kim@gmail.com; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675295282; h=from:from:sender: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=qONq/AhmclCCK7mKauzEac52VGve8IOohgS94o773p8=; b=4xDBJ7JvgsMg/O8tyZNFn4mXsyNJcZw21sr27s1ouSH45/4flMxu4ih2D3ygUkfh0xlhsa P4mPsvaEClNIt52PhSAqvv1SMIVk1LexM7mwKblJkEf+M1gjwZ1FIHzPJvvAZso1E0nLGS TXjSEdrcDDucmLhbxjwxDmxE/w2NRDM= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=IAPv2JXk; spf=pass (imf22.hostedemail.com: domain of minchan.kim@gmail.com designates 209.85.216.42 as permitted sender) smtp.mailfrom=minchan.kim@gmail.com; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675295282; a=rsa-sha256; cv=none; b=bXkC3MB2Az6fQLBfHw4rSu/NodIF4fUjEMBqwiinqLiumpnOYlAfOeNVLENPp0hm0fVr9Q +MASeNvyu8Ky89adyAEob39iM+wRKCd56GCrRMrv2kZ71Xd/arwSlhML8l/2E53XicgH6G 8XzsJ84e80Zf+vf5E2M+L1YxjMHLq+Y= Received: by mail-pj1-f42.google.com with SMTP id cl23-20020a17090af69700b0022c745bfdc3so194115pjb.3 for ; Wed, 01 Feb 2023 15:48:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:from:to:cc:subject:date:message-id :reply-to; bh=qONq/AhmclCCK7mKauzEac52VGve8IOohgS94o773p8=; b=IAPv2JXkez3tw3c5eqcIiuNepppxNz8R2Mra2NjPSCAkkuGYQQ/FoQMUxp86wepszE jNG7okLoYIcyo9iVNLrzvmG8La/VvG4O9MBt4TYQNQCs0EuZPZavwfxIov2N1O7hN13o Om9ZNwEue5xHE6CMWpAWfnKZjq4J19jIj7gCGy42Wn3AlVML5D6+OuX5k8hwCrvyOJBA lM/D6YMQ6zkrKEi7FPXCgPTSY6PeUUOughd6ZIDCUp56xFqQh/VK6YAY6FXxGMTGZoLn AAAPNr1VclfuI4FwLSbYO8DO1d7Q1Yye5hUk9ETETtEKXZptFfd1ibIbsVe/Z30htZ+h 4o3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qONq/AhmclCCK7mKauzEac52VGve8IOohgS94o773p8=; b=6MxAf22Nc+xSmq+cWFrh00Cx1LDWxF9lp0vYQvWw3bl4pm2LtH8Qp1NNB2lomdLwdj l1wA04rFocxWTQH7jhXlCOuSyt/hNdiplQbTl0R8Xkau60q47XQ+o18aOOO8HtPZTrON TO+MteenV3hJXuS1s19LKAbSdBJwVyXgSPBf72z4T2D/xFotHqXWyKvU9c9M9r7LOs/g kFDVJuOgCPhL88KEhLh7g4u8cIGs3MNVu7CF2yw6YE/WpTI6Ivre4UMErMSDDiw+PPvf gU1Lw2s0aHXlC49npkT7rOzZw2ZdVRzc5Ag3I1JR1CI3BX4Q6Xyirgv5A65NbsCsTayD lVKg== X-Gm-Message-State: AO0yUKWL1jx5WMuvtuqpznyf3LqBGxGmrRNZ6ehaj6NlZTrmTye3zdU8 ZR6pQFl3/dsfOwWnZXzjBpc= X-Google-Smtp-Source: AK7set82yy1P3qNgPucA+e/yxxzq7s64ng3Kgdc7ME8kRxyqYaIHFyCj4We60GWRUlN3gN70EsA4nA== X-Received: by 2002:a17:903:4053:b0:196:7eb6:8b21 with SMTP id n19-20020a170903405300b001967eb68b21mr3726989pla.23.1675295281331; Wed, 01 Feb 2023 15:48:01 -0800 (PST) Received: from google.com ([2620:15c:211:201:d784:e914:b18:b429]) by smtp.gmail.com with ESMTPSA id q8-20020a170902b10800b00194caf3ccc4sm1287197plr.285.2023.02.01.15.48.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 15:48:00 -0800 (PST) Date: Wed, 1 Feb 2023 15:47:58 -0800 From: Minchan Kim To: Chris Goldsworthy Cc: Roman Gushchin , Sukadev Bhattiprolu , Andrew Morton , Rik van Riel , Roman Gushchin , Vlastimil Babka , Joonsoo Kim , Georgi Djakov , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm,page_alloc,cma: configurable CMA utilization Message-ID: References: <20230131071052.GB19285@hu-sbhattip-lv.qualcomm.com> <20230131201001.GA8585@hu-sbhattip-lv.qualcomm.com> <20230201040628.GA3767@hu-cgoldswo-sd.qualcomm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230201040628.GA3767@hu-cgoldswo-sd.qualcomm.com> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 90C59C001D X-Stat-Signature: kyyp9xgdthiy43eog6tm6zwpn4kbmkwr X-Rspam-User: X-HE-Tag: 1675295282-494165 X-HE-Meta: U2FsdGVkX1/Icovq7uWcodS1SviuBjW/nud6mge4xcqzHIHg6BUnt0C/RmhoZFwKKMRqoBVRWKuQHa+I3Lc3XACVbx6242EkbVDKP1AWl8XQO65RDhzJBQA19KjeiAOCRTRsVNMI9A5rvDkuslm5FAo/21BD+c9gZmBcILeUEc4WTepS9blpulIGqCcIQrm8/EDT1AhIpUhYigXBVrxoMmIl/QznwXyFmbGfdfbayjvVzVCMHceBEYBzaoE5qvE0nUTILY+eVE//N+A+JMSr2KiD+R+T4Wl8df7KXcQxHE5cnD7yZjttUj8JyFT0ZXBOVoLKOZc6NKt2wZqHJJhJMv9xcZs2+ovlps3dxINFo2xIRcOlgudzy6GgWwGpXbltrBZp3ZUaU4qWDVzD9kyMCfzXxR2dwZc2TeDVvp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UWWUfNYLIatOj3C0wpbolxFtC/D/DarSullJo530lhI302Cb4jyjis/jI4sf7RjILs3YZ/JtAvcATbE40+eH0PRVsX0rINd0dR8N0xku X-Bogosity: Ham, tests=bogofilter, spamicity=0.000019, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hi Chris, On Tue, Jan 31, 2023 at 08:06:28PM -0800, Chris Goldsworthy wrote: > On Tue, Jan 31, 2023 at 03:59:36PM -0800, Roman Gushchin wrote: > > On Tue, Jan 31, 2023 at 12:10:01PM -0800, Sukadev Bhattiprolu wrote: > > > On Tue, Jan 31, 2023 at 10:10:40AM -0800, Roman Gushchin wrote: > > > > Hi Sukadev! > > > > > > > > Can you, please, share a bit more details about your setup? E.g. what is > > > > the zone size, the cma area size and the value you want to set your sysctl to? > > > > > > Hi Roman, > > > > > > I currently have a device with 8GB Zone normal and 600MB of CMA. We have a > > > slightly different implementation and use up all the available CMA region. > > > i.e. going forward, we intend to set the ratio to 100 or even higher. > > > Hi Roman, > > > It means you want allocations be always served from a cma region first? > > Exactly. > > > What's the point of it? > > We're operating in a resource constrained environment, and we want to maximize > the amount of memory free / headroom for GFP_KERNEL allocations on our SoCs, > which are especially important for DMA allocations that use an IOMMU. We need a > large amount of CMA on our SoCs for various reasons (e.g. for devices not > upstream of an IOMMU), but whilst that CMA memory is not in use, we want to > route all GFP_MOVABLE allocations to the CMA regions, which will free up memory > for GFP_KERNEL allocations. I like this patch for different reason but for the specific problem you mentioned, How about making reclaimer/compaction aware of the problem: IOW, when the GFP_KERNEL/DMA allocation happens but not enough memory in the zones, let's migrates movable pages in those zones into CMA area/movable zone if they are plenty of free memory. I guess you considered but did you observe some problems? > > > The idea behind the current formula is to keep cma regions free if there is > > a plenty of other free memory, otherwise treat it on par with other memory. > > With the current approach, if we have a large amount of movable memory allocated > that has not gone into the CMA regions yet, and a DMA use case starts that > causes the above condition to be met, we would head towards OOM conditions when > we otherwise could have delayed this with this change. Note that since we're > working on Android, there is a daemon built on top of PSI called LMKD that will > start killing things under memory pressure (before an OOM is actually reached) > in order to free up memory. This patch should then reduce kills accordingly for > a better user experience by keeping a larger set of background apps alive. When > a CMA allocation does occur and pages get migrated out, there is a similar > reduction in headroom (you probably already know this and know of the FB > equivalent made by Johannes Weiner). > > Thanks, > > Chris.