From patchwork Wed May 8 22:40:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13659212 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 4C6DEC04FFE for ; Wed, 8 May 2024 22:42:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D82B26B0095; Wed, 8 May 2024 18:42:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D322F6B0096; Wed, 8 May 2024 18:42:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BFA9C6B0098; Wed, 8 May 2024 18:42:02 -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 9F1046B0095 for ; Wed, 8 May 2024 18:42:02 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 2BF83120BD9 for ; Wed, 8 May 2024 22:42:02 +0000 (UTC) X-FDA: 82096702884.14.CDCF4EC Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) by imf03.hostedemail.com (Postfix) with ESMTP id 4487220011 for ; Wed, 8 May 2024 22:41:59 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=LiGAJxcj; spf=pass (imf03.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.216.45 as permitted sender) smtp.mailfrom=21cnbao@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=1715208119; 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=BKP4frf3SJsYj3bpFkLEvp3HW+vS2YimBRDSFS3kDwg=; b=5s/OnU7tDeWPS9IDHudC2X9j+V99K8tS/IdYsLi7TfZJg9UhBgKlVKT70O22/E40BC9KtW uwHjHSz33SPuyqyB8dN5MQZao/DUg3gJ+k8yJ0DPYQ5T7myp4t805zT23uGQhDaCjeZ7Jj HN8cwzmGgi6q/MVCO21YX6VUQIiAWS4= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=LiGAJxcj; spf=pass (imf03.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.216.45 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715208119; a=rsa-sha256; cv=none; b=5zUprCjZ/TfehDDGgYAeeIkn5nKgAwbBnUgHj22qaNZgaxVu7EArzWTQioEMz6OqGnV15L Aq/0ivKZe6lzcYblLY0K5nKTTIsX0X3L9+3V9q9LkhtZhTNJNhXQgRJ3vfFwrgDtfIYU+f J34C9PFQGXuKdyX5l5P9u7xRlE/UTyg= Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-2b432be5cc9so242230a91.3 for ; Wed, 08 May 2024 15:41:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715208118; x=1715812918; 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=BKP4frf3SJsYj3bpFkLEvp3HW+vS2YimBRDSFS3kDwg=; b=LiGAJxcjd00xHXnCLVxpPq1VVL9FwE9rcIo1IFQvwtr2pvlP1SPCaPtatkRMJcKCzK yDl7PNn8ujEnw3ZgzrzE/lMgEpAldMlPmllJ1C1xqHD5USrSwPzUEtNuqBit9KNcQZAU PFJjPP+3ik4fjRMeF8CTZ1IBW7JtCL4SUa/u6kJ32jgJXRw1qp43/oguSvCko8H2vlvE qCIQEzgPW/e4tjFO0A77lqRmrFDewv5KEXaqXBMxcoXTsNmNbnlR3/fnftYqu+UXxiCn fvkaCUm7GiffwHIlYVk2Fal+wqeZMHWQiGQTJMIKZsz98mUiRfVyeIGrJwa486jdQpXb mpzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715208118; x=1715812918; 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=BKP4frf3SJsYj3bpFkLEvp3HW+vS2YimBRDSFS3kDwg=; b=AGGbI34SpYKLWbxjxlvBjahSbWy2yqY2cNPugaAxt2uM+KQpHAHvSZ9/Ls3WKrUlsp V/vE4gCV71cos3kGsl5N+38KGQutA85gW8g48g6uvvcwQQVjSDZue9XUESJOu4491W6T 9SXqOIDGyWnf1m4VAz40tesUYBjlG0442jzjnyrL2TRZ242RNC+vTz9jQiPT2Cga6rbX ouxO8avn7km2fipWvN8dLDMvyWzIJFMwx6ZtKVxGtSvDmQ4gMgb9xQHkto6qh+mHJJf9 hDWiqvZJys8XXrRusVmVYzc106eFlgVH0Diiqu0kZrmMjJ3RS9tqFQ/O7ffwNjVWw+7J VyyQ== X-Forwarded-Encrypted: i=1; AJvYcCUBWbQS2CGEbWyauLPTfovjo6BJxPDrW2sDBghChsgP41pGOA57vw/i2cUoTEAD79lm5gfQIOfQqY5myS51IER9uAk= X-Gm-Message-State: AOJu0Yz8QECP1GYh355lXf9TF3wDWXdg89MHipyNippsceLWW4Au5a72 Z39KDm2lRRvGGuvYOMRJwjbU32AkICypZ70X1G//lSGD0SfZXc7Q X-Google-Smtp-Source: AGHT+IFi9srqYFLAGkCKh6k9BgPnyvD1B3mYyYQyZ3x2gIfLtku4oUuO4QjlFLxaj5GaZF8qFdK07w== X-Received: by 2002:a17:90b:894:b0:2b6:2138:e407 with SMTP id 98e67ed59e1d1-2b62138e4c9mr3786419a91.9.1715208118171; Wed, 08 May 2024 15:41:58 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2b67126b666sm102082a91.34.2024.05.08.15.41.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 15:41:57 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: baolin.wang@linux.alibaba.com, chrisl@kernel.org, david@redhat.com, hanchuanhua@oppo.com, hannes@cmpxchg.org, hughd@google.com, kasong@tencent.com, linux-kernel@vger.kernel.org, ryan.roberts@arm.com, surenb@google.com, v-songbaohua@oppo.com, willy@infradead.org, xiang@kernel.org, ying.huang@intel.com, yosryahmed@google.com, yuzhao@google.com, ziy@nvidia.com, "Rafael J. Wysocki" , Pavel Machek , Len Brown , Christoph Hellwig Subject: [PATCH v4 2/6] mm: remove the implementation of swap_free() and always use swap_free_nr() Date: Thu, 9 May 2024 10:40:36 +1200 Message-Id: <20240508224040.190469-3-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240508224040.190469-1-21cnbao@gmail.com> References: <20240508224040.190469-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Stat-Signature: nm16ie7cz8yt37eamd8req35iqgu36w4 X-Rspamd-Queue-Id: 4487220011 X-Rspamd-Server: rspam10 X-Rspam-User: X-HE-Tag: 1715208119-206963 X-HE-Meta: U2FsdGVkX1803TjMUwWq1Sf/xqRW1NWp5zT+frXgaR3RVM00PuIef/gG3uBKf5tnArFid7JyFYvsrlHKGm/7iq9RBsMLM0TUnP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ZHC8p6SRSO15rwK7Efir887Ipj5mgLH+Q93Ky5Em2uU9UMP7aRZjcusoEuGsUY3EaWRK9ZEMSXItMN4Z/2cdvSca5byKnpVFXKr17ICRFdmY3dNqH9k9e3+yn3N3TilX+G7uz32z+bkyiM1PQYEFTuioPJu1WONcyu6REfcTEQ14LzMvUV77tNzP2JDka4na0B1VIPktA9+tF9+f7QnfW8QL4wcwfCFcCeiGmDb3uVKS7WAiCWGLZU7UB5leDKzUVS3YYXu9T4X48KcZc2llYDvemaDSQMa34CCOic8grRE8zvLlfym/alpUAzG6RtGly/fTZ7Z9hithlRaW2zrhrxrDGvbYIgOJaR2BvnLqIkEGOb1wjdg9JdfVro77MvMwu3Zn3BX4BIa68XolTqeZzrt0qnqb3N4PO0INyvwEaJebqz3QQGJducqBxhPP7zvhoowrPDdubHzGl8sUQy8P3fSvuYEz8+GKqXZuhkiRDKNetRo2ltIDMDKAq+NlwyZllgCTY4JJ2ry0HjL/wYAs5jhrAfYLWkMPRF1gRtiaJmthwPhkNVocQL+kk8HA= 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: From: Barry Song To streamline maintenance efforts, we propose removing the implementation of swap_free(). Instead, we can simply invoke swap_free_nr() with nr set to 1. swap_free_nr() is designed with a bitmap consisting of only one long, resulting in overhead that can be ignored for cases where nr equals 1. A prime candidate for leveraging swap_free_nr() lies within kernel/power/swap.c. Implementing this change facilitates the adoption of batch processing for hibernation. Suggested-by: "Huang, Ying" Signed-off-by: Barry Song Reviewed-by: "Huang, Ying" Acked-by: Chris Li Cc: "Rafael J. Wysocki" Cc: Pavel Machek Cc: Len Brown Cc: Hugh Dickins Cc: Christoph Hellwig Reviewed-by: Ryan Roberts --- include/linux/swap.h | 10 +++++----- kernel/power/swap.c | 5 ++--- mm/swapfile.c | 17 ++++------------- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index d1d35e92d7e9..48131b869a4d 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -482,7 +482,6 @@ extern int add_swap_count_continuation(swp_entry_t, gfp_t); extern void swap_shmem_alloc(swp_entry_t); extern int swap_duplicate(swp_entry_t); extern int swapcache_prepare(swp_entry_t); -extern void swap_free(swp_entry_t); extern void swap_free_nr(swp_entry_t entry, int nr_pages); extern void swapcache_free_entries(swp_entry_t *entries, int n); extern void free_swap_and_cache_nr(swp_entry_t entry, int nr); @@ -561,10 +560,6 @@ static inline int swapcache_prepare(swp_entry_t swp) return 0; } -static inline void swap_free(swp_entry_t swp) -{ -} - static inline void swap_free_nr(swp_entry_t entry, int nr_pages) { } @@ -613,6 +608,11 @@ static inline void free_swap_and_cache(swp_entry_t entry) free_swap_and_cache_nr(entry, 1); } +static inline void swap_free(swp_entry_t entry) +{ + swap_free_nr(entry, 1); +} + #ifdef CONFIG_MEMCG static inline int mem_cgroup_swappiness(struct mem_cgroup *memcg) { diff --git a/kernel/power/swap.c b/kernel/power/swap.c index 5bc04bfe2db1..75bc9e3f9d59 100644 --- a/kernel/power/swap.c +++ b/kernel/power/swap.c @@ -200,12 +200,11 @@ void free_all_swap_pages(int swap) while ((node = swsusp_extents.rb_node)) { struct swsusp_extent *ext; - unsigned long offset; ext = rb_entry(node, struct swsusp_extent, node); rb_erase(node, &swsusp_extents); - for (offset = ext->start; offset <= ext->end; offset++) - swap_free(swp_entry(swap, offset)); + swap_free_nr(swp_entry(swap, ext->start), + ext->end - ext->start + 1); kfree(ext); } diff --git a/mm/swapfile.c b/mm/swapfile.c index ec12f2b9d229..99e701620562 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1343,19 +1343,6 @@ static void swap_entry_free(struct swap_info_struct *p, swp_entry_t entry) swap_range_free(p, offset, 1); } -/* - * Caller has made sure that the swap device corresponding to entry - * is still around or has not been recycled. - */ -void swap_free(swp_entry_t entry) -{ - struct swap_info_struct *p; - - p = _swap_info_get(entry); - if (p) - __swap_entry_free(p, entry); -} - static void cluster_swap_free_nr(struct swap_info_struct *sis, unsigned long offset, int nr_pages) { @@ -1385,6 +1372,10 @@ static void cluster_swap_free_nr(struct swap_info_struct *sis, unlock_cluster_or_swap_info(sis, ci); } +/* + * Caller has made sure that the swap device corresponding to entry + * is still around or has not been recycled. + */ void swap_free_nr(swp_entry_t entry, int nr_pages) { int nr;