From patchwork Sun Aug 21 15:40:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bui Quang Minh X-Patchwork-Id: 12949990 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 0212FC00140 for ; Sun, 21 Aug 2022 15:42:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 15F5B6B0073; Sun, 21 Aug 2022 11:42:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 10EF68E0001; Sun, 21 Aug 2022 11:42:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EF18D6B0075; Sun, 21 Aug 2022 11:42:04 -0400 (EDT) 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 D9CC16B0073 for ; Sun, 21 Aug 2022 11:42:04 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A62BB1A07C0 for ; Sun, 21 Aug 2022 15:42:04 +0000 (UTC) X-FDA: 79824015768.13.065F582 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by imf23.hostedemail.com (Postfix) with ESMTP id 6A38E140011 for ; Sun, 21 Aug 2022 15:42:04 +0000 (UTC) Received: by mail-pj1-f53.google.com with SMTP id m10-20020a17090a730a00b001fa986fd8eeso11763881pjk.0 for ; Sun, 21 Aug 2022 08:42:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc; bh=NH92h/s4Soe5U4MYFnUhteYLROiSYWktF09/ofBtT24=; b=EEpjWqUAEIYey8Vx3R4wQW1i+pIpveVzAYWhkuJVyzMlMcYSksW42gb9vVxdbdwtVt h0QEo2JaXKj7FU6/xva+F4kSIYiLdF1RlPh/v1ovJdDoR4aWPIM8ix203wijGolDJes+ N3aLkmyJDEIc3b5LOxUfHX4o9QCqrL3M8+KtFOMIDFxmjLEO4IP4w+l6uG9kesJTVH4A dNcBowT5h6WgyP/0KLj50U/ZvHFCdjWczm1URgw2IGtTJtRSDXvxLLzPIleWL8RcKPmT NuKzmIqtNvIginOpZUS0A9NMmF1A9R03GCZ8O35qY3GNAq9iTo8FC6+2wPuTKZUuCXtm XF8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=NH92h/s4Soe5U4MYFnUhteYLROiSYWktF09/ofBtT24=; b=MFQF8vFHbYSvCFA+hbDJVLskDRgXftVYTxkII0xEi82GFJc7cqWb31SWqayJoPyjpl lv7FHftNxy4kn21+N6JIOnvnEMDhuk9j7eRAc3DKW/d+pmJIPzOXBmxl1ftPnlzQa/IE LKYko9A1NtFI9Q3gXkPLs9jL4hDwKyW3UjZNrFI2ac3lXRPH/dilGa0UnBTzdChql98r Ycwef7RcKAC//gPirUeTCo93w9Um1/1KRrXoHwym8qT1WPiK1fY1gwz4axqKqyd3OmZM OhgvGId4pBeZGmusnUa6VlEAXU3nC4cLE/zzSLUDgNB6bH8WiUblRkSy+Bt51tA8XVuk TTEA== X-Gm-Message-State: ACgBeo1QYlxOmq4u5swHrmFFF8VQyiQDgYdG+ge0y/oRelD3S0BHy44m SC4RZTUKjUIxo+5crbXIyCE= X-Google-Smtp-Source: AA6agR6l42SoHMuJQdAcYlj27AjNpDt8CSJhgvwnKOIkUXvOvez9Pi4r8WAwKc2GqOGP9PiY45ZX5A== X-Received: by 2002:a17:902:ba96:b0:170:9f15:b997 with SMTP id k22-20020a170902ba9600b001709f15b997mr15889474pls.34.1661096523078; Sun, 21 Aug 2022 08:42:03 -0700 (PDT) Received: from localhost.localdomain ([113.172.183.227]) by smtp.googlemail.com with ESMTPSA id s10-20020aa78bca000000b00534e9aadbf7sm6857796pfd.182.2022.08.21.08.42.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 08:42:02 -0700 (PDT) From: Bui Quang Minh To: linux-kernel@vger.kernel.org Cc: Bui Quang Minh , Andrew Morton , linux-mm@kvack.org Subject: [PATCH] mm: Skip retry when new limit is not below old one in page_counter_set_max Date: Sun, 21 Aug 2022 22:40:55 +0700 Message-Id: <20220821154055.109635-1-minhquangbui99@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661096524; a=rsa-sha256; cv=none; b=m/bnxVY6TiZRsjpg0xVGAFkU8PqKvpPG0oIUNYxuRe5PbDE95QVpuXtNs9cUksGJOkrKZi 5Sba3b+6xKgghxGgPRydJgQolGgkH/v1mTE6MGt5JDmZ+svjElj/vmkr2EMKXxpjgURF+S J1W9/1cXegZB6OaCWFnzY8EG6f7PJ2U= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=EEpjWqUA; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf23.hostedemail.com: domain of minhquangbui99@gmail.com designates 209.85.216.53 as permitted sender) smtp.mailfrom=minhquangbui99@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661096524; 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:references:dkim-signature; bh=NH92h/s4Soe5U4MYFnUhteYLROiSYWktF09/ofBtT24=; b=pO6oKe97WKQhn2X62Dk0XWu4zADzH5YDqsxfRJQ7HWDfCM9kkbh1/hI2RUoNBSpsXHbMb8 IohdHfbWrE0wLRK8P2LARI/2YNkF4wQKnWBPS81mpOmwfMeoHM4i5v1v8IjIO4eEFUEXPC Yot780pw0qNeU6hd35PgOhqQt6WxqBk= X-Rspamd-Queue-Id: 6A38E140011 X-Stat-Signature: g9nb4wzygbf6o3izfow4q7rmj16jnaju Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=EEpjWqUA; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf23.hostedemail.com: domain of minhquangbui99@gmail.com designates 209.85.216.53 as permitted sender) smtp.mailfrom=minhquangbui99@gmail.com X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1661096524-664663 X-Bogosity: Ham, tests=bogofilter, spamicity=0.010500, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In page_counter_set_max, we want to make sure the new limit is not below the concurrently-changing counter value. We read the counter and check that the limit is not below the counter before the swap. After the swap, we read the counter again and retry in case the counter is incremented as this may violate the requirement. Even though the page_counter_try_charge can see the old limit, it is guaranteed that the counter is not above the old limit after the increment. So in case the new limit is not below the old limit, the counter is guaranteed to be not above the new limit too. We can skip the retry in this case to optimize a little bit. Signed-off-by: Bui Quang Minh --- mm/page_counter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/page_counter.c b/mm/page_counter.c index eb156ff5d603..8a0cc24b60dd 100644 --- a/mm/page_counter.c +++ b/mm/page_counter.c @@ -193,7 +193,7 @@ int page_counter_set_max(struct page_counter *counter, unsigned long nr_pages) old = xchg(&counter->max, nr_pages); - if (page_counter_read(counter) <= usage) + if (page_counter_read(counter) <= usage || nr_pages >= old) return 0; counter->max = old;