From patchwork Wed Dec 25 02:10:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zihan zhou <15645113830zzh@gmail.com> X-Patchwork-Id: 13920886 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 7D7E3E7718D for ; Wed, 25 Dec 2024 23:56:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0F2AC6B007B; Wed, 25 Dec 2024 18:56:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 07B696B0085; Wed, 25 Dec 2024 18:56:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E6A166B0083; Wed, 25 Dec 2024 18:56:05 -0500 (EST) 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 3C4DF6B0082 for ; Tue, 24 Dec 2024 21:11:24 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 8FDD0AEB12 for ; Wed, 25 Dec 2024 02:11:23 +0000 (UTC) X-FDA: 82931853984.28.8A6E183 Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) by imf27.hostedemail.com (Postfix) with ESMTP id 5C4AD40006 for ; Wed, 25 Dec 2024 02:10:38 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=my3kVRbE; spf=pass (imf27.hostedemail.com: domain of 15645113830zzh@gmail.com designates 209.85.214.194 as permitted sender) smtp.mailfrom=15645113830zzh@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1735092644; a=rsa-sha256; cv=none; b=TtE1496rBCeFVawT6KFHenmPhhzpZvMpefOes48BJz2N4qZWOIbeHry/PYMMKbY85k7kLI oEFO9VgpQYQg0gGr1Ry7U5Es/8p+fskyAu91VznPFiZv1Wb/P2KJtYeu/BVXER9Pnb5VLb FVEMO4NWeLfACwr2Qef9n4VpJ4XHbgY= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=my3kVRbE; spf=pass (imf27.hostedemail.com: domain of 15645113830zzh@gmail.com designates 209.85.214.194 as permitted sender) smtp.mailfrom=15645113830zzh@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1735092644; 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=dPkTj4/mfObVqG6KGvl+PDwTOeV/bbGGDXdKyCnoK8Q=; b=IMeYCKf4HHgl3TH+t/w1vuE5UmYaRsuQg7KM/5aozY1CjxzbHn7QnkNKDUqiarXZrOyxvM 5bdOzRoUrEjypv9+7ii3y9u6fXPs0vVFaAT+yiPZYo0XjGKxPR7Bq6FxBYdt458pYVxgUF LBuJbzCbc4PEZfWy5LCEDplUS1seA6o= Received: by mail-pl1-f194.google.com with SMTP id d9443c01a7336-216426b0865so58014165ad.0 for ; Tue, 24 Dec 2024 18:11:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735092680; x=1735697480; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=dPkTj4/mfObVqG6KGvl+PDwTOeV/bbGGDXdKyCnoK8Q=; b=my3kVRbEX8akmiW40uiwknbryYLmnKov7xEKoCq34To8AXLxcntOHVq7eo3AVMIcvp 1vbZ0rJqb5y+HS22f5pb6kaDrvAOHNuZ+mS8KLdCfkltUUUmZxbd2+cwWjML/6VbuwSs NTJLqgNPQ0vZiSpPwmAOhxDHFDka/ffYHoRi+1K0LUVRVyJqnIEsbUKopX2KI3UNkOL0 5t0c97OhNcQhzHZJlOJdzdMlWv3EQfo5uweQmNOk5iNZ5hWg65V614uM6mKja7/Z3WqY WROvqWc3lamGM8j38gavrohjDekFdROC+RqD/HFq8ufGFFiHPJwvPyo0tmWyWIWxhq3Z G+Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735092680; x=1735697480; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=dPkTj4/mfObVqG6KGvl+PDwTOeV/bbGGDXdKyCnoK8Q=; b=DdyvGRQO7T21BFBmTaA/O+es79QeLLvvFhHuAgg5Z6STVWY6IXTTfZZOfPlb0/1hYh jfU/itfBAl+QmuplXRDjoEU9J87kmtUg/+MzgJgLk9lCXtDG9Cgl6L4lTK/FzmeExpeM DABiJn2dudT5rQ5pGEBSuVJD9JRM2YL5VWl1x5udf6gCIBvTKEZ8NaE8o6H26yO2iS7t ckjKGYMEN+dSfXOpDSHsozVXm1lh1jCK3Qe5rjTtjk1e0ogwaJISKEyIeTSM2MuF2Fce UiUHBRORRiPgM+JdLIVvUX944nIC7LjywqKUl+Xqj5vtWmjBII+03ngm6j4qREquhY9c 4xaQ== X-Forwarded-Encrypted: i=1; AJvYcCVu8RAKG1/jzpk5QWX0OY7bhyKAIvDTzhuzdzwbMwxo8Bol8SU2NB+Y0fvULMJs+yH0UD7LhD0/OA==@kvack.org X-Gm-Message-State: AOJu0YzaoY/pshBi/OtbM7kJf4q8Hr0yU2/yZQRFsyfYSo4L2p1UFF7D qWPFyoRW00yX3eyc/2cBvlBTX47gMQtnOXd4KRyodjWJ2HhuPcH8 X-Gm-Gg: ASbGncsGWviK589qqO+wlxVLdthDqkmOaopFqD7ojdLKJ7aDi51bt9pe0b9yuhe3vwo CoBz/es1Nl+Mo4z+PCzPe4SXmqru6CaQUrZ/ubMIhyl6ShnqrGo+bobwY8BbQDG673q5msNT90Y S+3ExE1k1mpmagoK6tpTHtqJO4n6dhn3B3sv9dDd0SuS6g5y8P5S1MVnEHYG9BcWyV01c2ALssV igbM7Y+bxIH6JIt47BqAUxUf4QFK+2kqPpty9E/KiU7pRALlofdxTCVvQ/oQ9R0/zwy2wejbuiw 0S9vd5rL/g== X-Google-Smtp-Source: AGHT+IGG7SYTbjed3f2ooAtVTBLj/P7loSZ548JbFtGZpxJhfqEEq3ErT01E/bPY+TVfysE16K6tng== X-Received: by 2002:a05:6a00:44c4:b0:725:e405:6df7 with SMTP id d2e1a72fcca58-72abdd7f683mr27675919b3a.10.1735092680166; Tue, 24 Dec 2024 18:11:20 -0800 (PST) Received: from localhost.localdomain ([2408:80e0:41fc:0:fe2d:0:3:6253]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72aad8fd4e2sm10319011b3a.169.2024.12.24.18.11.17 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 24 Dec 2024 18:11:19 -0800 (PST) From: zihan zhou <15645113830zzh@gmail.com> To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, zihan zhou <15645113830zzh@gmail.com>, yaowenchao Subject: [PATCH V1] mm: page_alloc: fix missed updates of lowmem_reserve in adjust_managed_page_count Date: Wed, 25 Dec 2024 10:10:35 +0800 Message-Id: <20241225021034.45693-1-15645113830zzh@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) MIME-Version: 1.0 X-Rspamd-Queue-Id: 5C4AD40006 X-Stat-Signature: mnwa46ccui1zhtx1modyhdjok8kf69de X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1735092638-494775 X-HE-Meta: U2FsdG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IYirztjH1rwJgeB+ceQ8pQ+1s9ESxJQCVL11vxlRc/2/J+DtfD1bZqXUWgX5Icw4BGfQecoiTetxtnK1P2HWjdtTxxWnKfQRoPyAbl/6z2hQyPlgB8Rqx8E2RBpk0yW+PM2r+jjOQmi1GGv9ok8jAUsKHXEeZRZoZfI+3OHBpyDWPimad7jBibtQ0DFoNC9DUhL3fhuNfxP/TlE9RLrYKoNcW8ekje1Aum6bclqCH8zWngmQWj6chgSI7YVw5i7UJiLbd80j1tnBjIRztbP8jLdOs876T6o0RIy3CCfSzqOHUHum6Srsk1SqpU27XNe/pPAiEQw8iiB/89eZvJ5Xg/6JRZnG+dxnYoB0Jd84d+LknnboxRS2jeSTBSRGAGfZn1EF4EDtwAeIoOpHBT3D/zLt4hRFQyBgfVGBJ5kgEr7U6k6VT7MRVd3MleJ2en6glKlfPEWqYcKLFQaVMfGmit 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: In the kernel, the zone's lowmem_reserve and _watermark, and the global variable 'totalreserve_pages' depend on the value of managed_pages, but after running adjust_managed_page_count, these values didn't updated, which caused some problems. For example, in a system with six 1GB large pages, we found that the value of protection in zoneinfo (zone->lowmem_reserve), is not right. Its value seems calculated from the initial managed_pages, but after the managed_pages changed, was not updated. Only after reading the file /proc/sys/vm/lowmem_reserve_ratio, updates happen. read file /proc/sys/vm/lowmem_reserve_ratio: lowmem_reserve_ratio_sysctl_handler ----setup_per_zone_lowmem_reserve --------calculate_totalreserve_pages protection changed after reading file: [root@test ~]# cat /proc/zoneinfo | grep protection protection: (0, 2719, 57360, 0) protection: (0, 0, 54640, 0) protection: (0, 0, 0, 0) protection: (0, 0, 0, 0) [root@test ~]# cat /proc/sys/vm/lowmem_reserve_ratio 256 256 32 0 [root@test ~]# cat /proc/zoneinfo | grep protection protection: (0, 2735, 63524, 0) protection: (0, 0, 60788, 0) protection: (0, 0, 0, 0) protection: (0, 0, 0, 0) lowmem_reserve increased also makes the totalreserve_pages increased, which causes a decrease in available memory. The one above is just a test machine, and the increase is not significant. On our online machine, the reserved memory will increase by several GB due to reading this file. It is clearly unreasonable to cause a sharp drop in available memory just by reading a file. In this patch, we update reserve memory when update managed_pages, The size of reserved memory becomes stable. But it seems that the _watermark should also be updated along with the managed_pages. We have not done it because we are unsure if it is reasonable to set the watermark through the initial managed_pages. If it is not reasonable, we will propose new patch. Signed-off-by: zihan zhou <15645113830zzh@gmail.com> Signed-off-by: yaowenchao --- mm/page_alloc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index b6958333054d..b23e128afbcd 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5826,10 +5826,13 @@ __meminit void zone_pcp_init(struct zone *zone) zone->present_pages, zone_batchsize(zone)); } +static void setup_per_zone_lowmem_reserve(void); + void adjust_managed_page_count(struct page *page, long count) { atomic_long_add(count, &page_zone(page)->managed_pages); totalram_pages_add(count); + setup_per_zone_lowmem_reserve(); } EXPORT_SYMBOL(adjust_managed_page_count);