Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp3120202lqp; Mon, 25 Mar 2024 22:49:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXq/SCE1JJg4xUzbvwuAfaYfYZ7WV806EtkvbSOYWDo7Oz2fecp//TrXATVRX1gQ3I28+9w2I/dJuOSt/8e4ugsG2I0bM/j25M73yQ4Zg== X-Google-Smtp-Source: AGHT+IFV+I0o9TlU2vrw1jzBZor0sgOU/CgUIg4kZbvMGNLlV4vQ27e2BZcg2OdSwfcHRBcA2D9H X-Received: by 2002:a17:902:dacc:b0:1e0:c7b6:ef4a with SMTP id q12-20020a170902dacc00b001e0c7b6ef4amr4071296plx.40.1711432193473; Mon, 25 Mar 2024 22:49:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711432193; cv=pass; d=google.com; s=arc-20160816; b=W0ftZuBShWWfQe1knTw1ErT7G0rn1m6rWhIvEjJBc/SG+uYHYVBE0eBHa6t5UpV3rc pdoTpLcbO2M8FQ2MY5t2uGzYyzLuT/MzBtwEYv+cd/sZpfWGGf1fFgmwmBFR2nuTHgjH jI1sTE0unjkweZ7dlgQRwDpTLWBO4hWZ+O0kfQ/AwaFki+DPweKikr2vJtluaf3MW1Ky Jl+M/PGx0+F48h0arhxRFL2y0kYUI1QaqNwdxUOrYFbfYxm9eJSQ3yzm4ZqhqDekKxBq Cs0+c6hARy1OOOBiWJALjeLJ/p0zohajoN459MMdYMvkWw279pfg7TG404Ln8i+SAtWp RStg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:message-id:date:references:in-reply-to:subject:cc:to :from:dkim-signature; bh=U94F2/aNshjYEBnzta6NBuPBopsxkPMMFIM1gE3S6pw=; fh=I4bH3BuwVcNY+RYWP5hljbs86MDS2hnwVi4k1qwqpjA=; b=s48nL1V5G+Ddg7FYR6Sf84FYg3v3Fbbh6V9vCXa6+Hr68Oinl53O4OuJmeEAJSFLDz DpIsAI9wWvJ5CSYbOACJHLbXkkrr0C33AbALHbHxNlxb6mPHEpZ4mpYqIUVflfsgtScV 8TO71Fc2y5El6cTN58jRih5h0I8/O++haot7Ncy8UXC4YNCnN045xGH71XmmPHwvnjqf IAnWvBznkyPivYZkpc6j33jraCJKP9I8GdxuoDkoSyMUEsTIUyG1HGGpXf02g+2ayBOx YDN8XymTxFIRO+boTBtf8GmNZrXqfkrlC8WYQsjy3yUFt/fuGQvQFfK2Jq3qeAYOi7Il RHdQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ACd+WhCt; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-118382-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-118382-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id y2-20020a17090322c200b001e0b5744228si4578780plg.204.2024.03.25.22.49.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 22:49:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-118382-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ACd+WhCt; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-118382-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-118382-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id D7F982E127C for ; Tue, 26 Mar 2024 05:49:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6F65612AAD1; Tue, 26 Mar 2024 05:49:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ACd+WhCt" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53DDE446BA; Tue, 26 Mar 2024 05:49:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711432184; cv=none; b=c5serInLsy7cm79a9joU1lW3vzkxGf+xLFt2K/GLLEMP/Y0e/38u6w2rZ2l5hGy2qG/Ol6nKciOxlPVxYaBVPvlj/LEjylqHRLU2q3nJtUXEm3iN432QuOtf16Ar1TRiS86bBOzyHkkaZ+hkv80UXlNW4ALZ0p624JPwwAKJ81s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711432184; c=relaxed/simple; bh=p/gg9KAgQm2GHyb3MW5nLJXzf2/0LAbSene85/boffI=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=S3Pn4MxX6KnTZ4uk9HjdbJ2eZocY5zumOCNajiVcX8bVMQ23pV2whXM2sOHfECtlxsSshXv4/C32Wxy6q9NlF0PSiZY+3UkFezBvBfKNbTQuTdtha8CgkrrW5K3BOL2835SIXnkleRkwON8nqzUlXm5YzK+Xfa7yYmJ/OLR2x5A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ACd+WhCt; arc=none smtp.client-ip=192.198.163.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711432182; x=1742968182; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=p/gg9KAgQm2GHyb3MW5nLJXzf2/0LAbSene85/boffI=; b=ACd+WhCtkXRbSWvjB0Zd3qXZx3gPF3VZ9J33xFDmaoiXKqrw7LnfVejC jXS33+9pThcM04vLAHFhTDgEwOUqoJdq+Waw56igaBOFQ2hm9rHeaxeBD huefjFovKUNEzcW8OFvBSGpPVUGX0XvSI5wvF7yUJgogfotpjEz7n0kW1 MjT3+UXKFkD/uKWq+rgjeaT2S9vT4x0nG+TGnHAgCI6JnT2BGQvDtazKo SgWgddx77UflunHSEWoKBv5F711nQ692VTB2h18XK74fc2+HUHoPWuA9Y W7jPBhJnuVKOPYe0vQTBRPoGgDgoQmFnZV27+ipQ54o3anoKHy/EpOWGZ g==; X-IronPort-AV: E=McAfee;i="6600,9927,11024"; a="6676534" X-IronPort-AV: E=Sophos;i="6.07,155,1708416000"; d="scan'208";a="6676534" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2024 22:49:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,155,1708416000"; d="scan'208";a="16243888" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by orviesa007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2024 22:49:39 -0700 From: "Huang, Ying" To: Johannes Weiner Cc: linux-mm@kvack.org, david@redhat.com, hughd@google.com, osandov@fb.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH] mm: swapfile: fix SSD detection with swapfile on btrfs In-Reply-To: <20240322164956.422815-1-hannes@cmpxchg.org> (Johannes Weiner's message of "Fri, 22 Mar 2024 12:42:21 -0400") References: <20240322164956.422815-1-hannes@cmpxchg.org> Date: Tue, 26 Mar 2024 13:47:45 +0800 Message-ID: <87plvho872.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=ascii Hi, Johannes, Johannes Weiner writes: > +static struct swap_cluster_info *setup_clusters(struct swap_info_struct *p, > + unsigned char *swap_map) > +{ > + unsigned long nr_clusters = DIV_ROUND_UP(p->max, SWAPFILE_CLUSTER); > + unsigned long col = p->cluster_next / SWAPFILE_CLUSTER % SWAP_CLUSTER_COLS; > + struct swap_cluster_info *cluster_info; > + unsigned long i, j, k, idx; > + int cpu, err = -ENOMEM; > + > + cluster_info = kvcalloc(nr_clusters, sizeof(*cluster_info), GFP_KERNEL); > if (!cluster_info) > - return nr_extents; > + goto err; > + > + for (i = 0; i < nr_clusters; i++) > + spin_lock_init(&cluster_info[i].lock); > > + p->cluster_next_cpu = alloc_percpu(unsigned int); > + if (!p->cluster_next_cpu) > + goto err_free; > + > + /* Random start position to help with wear leveling */ > + for_each_possible_cpu(cpu) > + per_cpu(*p->cluster_next_cpu, cpu) = > + get_random_u32_inclusive(1, p->highest_bit); > + > + p->percpu_cluster = alloc_percpu(struct percpu_cluster); > + if (!p->percpu_cluster) > + goto err_free; > + > + for_each_possible_cpu(cpu) { > + struct percpu_cluster *cluster; > + > + cluster = per_cpu_ptr(p->percpu_cluster, cpu); > + cluster_set_null(&cluster->index); > + } > + > + /* > + * Mark unusable pages as unavailable. The clusters aren't > + * marked free yet, so no list operations are involved yet. > + */ > + for (i = 0; i < round_up(p->max, SWAPFILE_CLUSTER); i++) > + if (i >= p->max || swap_map[i] == SWAP_MAP_BAD) > + inc_cluster_info_page(p, cluster_info, i); If p->max is large, it seems better to use an loop like below? for (i = 0; i < swap_header->info.nr_badpages; i++) { /* check i and inc_cluster_info_page() */ } in most cases, swap_header->info.nr_badpages should be much smaller than p->max. > + > + cluster_list_init(&p->free_clusters); > + cluster_list_init(&p->discard_clusters); > > /* > * Reduce false cache line sharing between cluster_info and > @@ -2994,7 +3019,13 @@ static int setup_swap_map_and_extents(struct swap_info_struct *p, > idx); > } > } > - return nr_extents; > + > + return cluster_info; > + > +err_free: > + kvfree(cluster_info); > +err: > + return ERR_PTR(err); > } > [snip] -- Best Regards, Huang, Ying