From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 56D7B748D for ; Thu, 9 Jan 2025 04:05:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736395509; cv=none; b=PHu3S5QcohKgWD8fklMuSkc9Y3OfuOO6M6gwKJZAnWKUB3zrGvjXJ7RN5pX0UqVTz8anDvaTDW2uV1mz3lMzuNBf7dvmlLW5YV3TTKz7yIsmgGH9wL96a8FPk+ao+juZId/CHBlG0wTOdaafa4jg/9S3jYx6WgTbESVwxCTK94o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736395509; c=relaxed/simple; bh=IRE8hXz+8LP/hmhwrd3l71j4xcUByDggJxnLGDyCKr8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=de7uJMyLp3GkSinv7VZRuNoCu4mlwv8nv+tDydVe7ikMX6yVZBTQ9LIPfYVEVDAYnqQ6jUMPADwRViFvPqVU/0E364/3nvign35zaVMTHbWl5zSVTU+xRXrjT18zsl8QBOdncqL7bBdjWOWVJ3ATGr23t99W7xxuRZdXbelCpxw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=TjJLQubM; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TjJLQubM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736395505; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Heh7PR+7tVAH8KEF5f0RmJaGucOc6ZlxH2lKixXCaN4=; b=TjJLQubMAktgAdwqMcEXp4p7DtHPJgx/i0iMBeGoWKrPQspN+bSwA8gEFL4E/8IJIqSuW5 FrscBC8F/YXQXg/SJ425aGCF8nNzZpT+I+kWc6XjYDaccctDYi38QpbTzRZ/Nwaxipc0co J7lRwhc4Gtxm5He39Zgzd4AsU/OqYQk= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-662-HzTtlziPPCaRaQDbxqcXCQ-1; Wed, 08 Jan 2025 23:05:01 -0500 X-MC-Unique: HzTtlziPPCaRaQDbxqcXCQ-1 X-Mimecast-MFC-AGG-ID: HzTtlziPPCaRaQDbxqcXCQ Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B68941979053; Thu, 9 Jan 2025 04:04:57 +0000 (UTC) Received: from localhost (unknown [10.72.112.99]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4CCCB19560B9; Thu, 9 Jan 2025 04:04:54 +0000 (UTC) Date: Thu, 9 Jan 2025 12:04:49 +0800 From: Baoquan He To: Kairui Song Cc: linux-mm@kvack.org, Andrew Morton , Chris Li , Barry Song , Ryan Roberts , Hugh Dickins , Yosry Ahmed , "Huang, Ying" , Nhat Pham , Johannes Weiner , Kalesh Singh , linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 01/13] mm, swap: minor clean up for swap entry allocation Message-ID: References: <20241230174621.61185-1-ryncsn@gmail.com> <20241230174621.61185-2-ryncsn@gmail.com> 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=us-ascii Content-Disposition: inline In-Reply-To: <20241230174621.61185-2-ryncsn@gmail.com> X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 On 12/31/24 at 01:46am, Kairui Song wrote: > From: Kairui Song > > Direct reclaim can skip the whole folio after reclaimed a set of > folio based slots. Also simplify the code for allocation, reduce > indention. > > Signed-off-by: Kairui Song > --- > mm/swapfile.c | 59 +++++++++++++++++++++++++-------------------------- > 1 file changed, 29 insertions(+), 30 deletions(-) This actually can be split as two patches. Anyway, Reviewed-by: Baoquan He > > diff --git a/mm/swapfile.c b/mm/swapfile.c > index b0a9071cfe1d..f8002f110104 100644 > --- a/mm/swapfile.c > +++ b/mm/swapfile.c > @@ -604,23 +604,28 @@ static bool cluster_reclaim_range(struct swap_info_struct *si, > unsigned long start, unsigned long end) > { > unsigned char *map = si->swap_map; > - unsigned long offset; > + unsigned long offset = start; > + int nr_reclaim; > > spin_unlock(&ci->lock); > spin_unlock(&si->lock); > > - for (offset = start; offset < end; offset++) { > + do { > switch (READ_ONCE(map[offset])) { > case 0: > - continue; > + offset++; > + break; > case SWAP_HAS_CACHE: > - if (__try_to_reclaim_swap(si, offset, TTRS_ANYWAY | TTRS_DIRECT) > 0) > - continue; > - goto out; > + nr_reclaim = __try_to_reclaim_swap(si, offset, TTRS_ANYWAY | TTRS_DIRECT); > + if (nr_reclaim > 0) > + offset += nr_reclaim; > + else > + goto out; > + break; > default: > goto out; > } > - } > + } while (offset < end); > out: > spin_lock(&si->lock); > spin_lock(&ci->lock); > @@ -838,35 +843,30 @@ static unsigned long cluster_alloc_swap_entry(struct swap_info_struct *si, int o > &found, order, usage); > frags++; > if (found) > - break; > + goto done; > } > > - if (!found) { > + /* > + * Nonfull clusters are moved to frag tail if we reached > + * here, count them too, don't over scan the frag list. > + */ > + while (frags < si->frag_cluster_nr[order]) { > + ci = list_first_entry(&si->frag_clusters[order], > + struct swap_cluster_info, list); > /* > - * Nonfull clusters are moved to frag tail if we reached > - * here, count them too, don't over scan the frag list. > + * Rotate the frag list to iterate, they were all failing > + * high order allocation or moved here due to per-CPU usage, > + * this help keeping usable cluster ahead. > */ > - while (frags < si->frag_cluster_nr[order]) { > - ci = list_first_entry(&si->frag_clusters[order], > - struct swap_cluster_info, list); > - /* > - * Rotate the frag list to iterate, they were all failing > - * high order allocation or moved here due to per-CPU usage, > - * this help keeping usable cluster ahead. > - */ > - list_move_tail(&ci->list, &si->frag_clusters[order]); > - offset = alloc_swap_scan_cluster(si, cluster_offset(si, ci), > - &found, order, usage); > - frags++; > - if (found) > - break; > - } > + list_move_tail(&ci->list, &si->frag_clusters[order]); > + offset = alloc_swap_scan_cluster(si, cluster_offset(si, ci), > + &found, order, usage); > + frags++; > + if (found) > + goto done; > } > } > > - if (found) > - goto done; > - > if (!list_empty(&si->discard_clusters)) { > /* > * we don't have free cluster but have some clusters in > @@ -904,7 +904,6 @@ static unsigned long cluster_alloc_swap_entry(struct swap_info_struct *si, int o > goto done; > } > } > - > done: > cluster->next[order] = offset; > return found; > -- > 2.47.1 > >