Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1358730imm; Mon, 9 Jul 2018 23:55:07 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcG1Apr2hrKVsXDCQzvnFl4HZqLTxSouH9w2kx/qXF+CVxhvHxBiG3ieahAIlgjagdqyNOl X-Received: by 2002:a63:8548:: with SMTP id u69-v6mr12187064pgd.346.1531205707078; Mon, 09 Jul 2018 23:55:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531205707; cv=none; d=google.com; s=arc-20160816; b=OQ2LmXGuwPOEWXK13WeJstjIGbGpzOGqHGLXS+ofME52elOyuExD2mlhQfNgAV8G/B hTadD/QORFWigFRd12ZAjk3QhU7LXnKfvY5tR65OgPHXP/KL1IkaQzRIcsD58CDxLov2 OxbfI8I7SK4mXfB7oS2PzhTiwZ3+yygkj7aQww3QmdsrcbqVhi2JgZhU5HANbv2j1/9i 6km22d/ChfqBm3S8M3GVfuE7byX0Z9kpOWFUxk4QNOFAiI6/CITAOYKHVYo/7zn1lMcL NFA14RO9Nt+mLZbXaASGtqtEVDk9qADS2BqQXiVy3h4mttcWMRzrElAzDLqZHpSJn6KM EFQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from :arc-authentication-results; bh=yDBmHbpQNq0RoUjwg+6KWTCw2nngYG0A6RKh6Gbgq9A=; b=fUx+pxyG8HWq244ZrMrX61k4/o4lx2/40uOQb+RnLIMqXC0OERGp47eNdaIfPBbL6r rSMx0rIqn3s1mBgJc1qjZKrrtA4CXHqud7YhxKhgC96k+b0Aabiu0cTomSYxpEGnFCDw yNhhZABTyXgl5U1hOO9ZtJdL5NN45Edom4eliOrD/bxfzja4+6J3W+umsRlHHSdsO87K 02KfuGlSM2ZkwjGkm/gH8Ufu15/LZEqE1nEPY6VKbkUSrlOE+ToEFVjvJkzNv4ofD+Vb +yORycvk2Yo/fukCFOAOY79rLfbgtdaGSYKaVaALEznZ8/prbEEx5Ep9IXlBzm/VTd2L iQhQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i14-v6si14328784pgp.155.2018.07.09.23.54.52; Mon, 09 Jul 2018 23:55:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754332AbeGJGxk (ORCPT + 99 others); Tue, 10 Jul 2018 02:53:40 -0400 Received: from mga04.intel.com ([192.55.52.120]:17900 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751017AbeGJGxi (ORCPT ); Tue, 10 Jul 2018 02:53:38 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Jul 2018 23:53:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,333,1526367600"; d="scan'208";a="65628110" Received: from yhuang-dev.sh.intel.com (HELO yhuang-dev) ([10.239.13.118]) by fmsmga002.fm.intel.com with ESMTP; 09 Jul 2018 23:53:35 -0700 From: "Huang\, Ying" To: Dave Hansen Cc: Andrew Morton , , , "Kirill A. Shutemov" , Andrea Arcangeli , Michal Hocko , Johannes Weiner , "Shaohua Li" , Hugh Dickins , Minchan Kim , Rik van Riel , Naoya Horiguchi , Zi Yan , Daniel Jordan Subject: Re: [PATCH -mm -v4 04/21] mm, THP, swap: Support PMD swap mapping in swapcache_free_cluster() References: <20180622035151.6676-1-ying.huang@intel.com> <20180622035151.6676-5-ying.huang@intel.com> Date: Tue, 10 Jul 2018 14:53:35 +0800 In-Reply-To: (Dave Hansen's message of "Mon, 9 Jul 2018 10:11:57 -0700") Message-ID: <874lh7intc.fsf@yhuang-dev.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Dave Hansen writes: >> +#ifdef CONFIG_THP_SWAP >> +static inline int cluster_swapcount(struct swap_cluster_info *ci) >> +{ >> + if (!ci || !cluster_is_huge(ci)) >> + return 0; >> + >> + return cluster_count(ci) - SWAPFILE_CLUSTER; >> +} >> +#else >> +#define cluster_swapcount(ci) 0 >> +#endif > > Dumb questions, round 2: On a CONFIG_THP_SWAP=n build, presumably, > cluster_is_huge()=0 always, so cluster_swapout() always returns 0. Right? > > So, why the #ifdef? #ifdef here is to reduce the code size for !CONFIG_THP_SWAP. >> /* >> * It's possible scan_swap_map() uses a free cluster in the middle of free >> * cluster list. Avoiding such abuse to avoid list corruption. >> @@ -905,6 +917,7 @@ static void swap_free_cluster(struct swap_info_struct *si, unsigned long idx) >> struct swap_cluster_info *ci; >> >> ci = lock_cluster(si, offset); >> + memset(si->swap_map + offset, 0, SWAPFILE_CLUSTER); >> cluster_set_count_flag(ci, 0, 0); >> free_cluster(si, idx); >> unlock_cluster(ci); > > This is another case of gloriously comment-free code, but stuff that > _was_ covered in the changelog. I'd much rather have code comments than > changelog comments. Could we fix that? > > I'm generally finding it quite hard to review this because I keep having > to refer back to the changelog to see if what you are doing matches what > you said you were doing. Sure. Will fix this. >> @@ -1288,24 +1301,30 @@ static void swapcache_free_cluster(swp_entry_t entry) >> >> ci = lock_cluster(si, offset); >> VM_BUG_ON(!cluster_is_huge(ci)); >> + VM_BUG_ON(!is_cluster_offset(offset)); >> + VM_BUG_ON(cluster_count(ci) < SWAPFILE_CLUSTER); >> map = si->swap_map + offset; >> - for (i = 0; i < SWAPFILE_CLUSTER; i++) { >> - val = map[i]; >> - VM_BUG_ON(!(val & SWAP_HAS_CACHE)); >> - if (val == SWAP_HAS_CACHE) >> - free_entries++; >> + if (!cluster_swapcount(ci)) { >> + for (i = 0; i < SWAPFILE_CLUSTER; i++) { >> + val = map[i]; >> + VM_BUG_ON(!(val & SWAP_HAS_CACHE)); >> + if (val == SWAP_HAS_CACHE) >> + free_entries++; >> + } >> + if (free_entries != SWAPFILE_CLUSTER) >> + cluster_clear_huge(ci); >> } > > Also, I'll point out that cluster_swapcount() continues the horrific > naming of cluster_couunt(), not saying what the count is *of*. The > return value doesn't help much: > > return cluster_count(ci) - SWAPFILE_CLUSTER; We have page_swapcount() for page, swp_swapcount() for swap entry. cluster_swapcount() tries to mimic them for swap cluster. But I am not good at naming in general. What's your suggestion? Best Regards, Huang, Ying