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 04BA53E51F5 for ; Mon, 12 Oct 2026 14:08:11 +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=1791814093; cv=none; b=HLGSQ+lGdfu3rYdnDYpAugVZ2WYwSm5drcFbel0yCTAjEIpmgKo5M63LU8opRCzMHShCykvukZWRPUxvFNVXxsTNspBjFMyrim655vbWhaJB+IwYOfmiO7oGMl/6heAAjJ02WdgCkk3Z5/LQ4/XzSMbvN1/dcdFh9Ugbz1E1RuY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791814093; c=relaxed/simple; bh=65m8O5mMAysYzXHjOERw/ZWKQAGuHF9zBZvHMkIvbKI=; h=Date:From:To:cc:Subject:Message-ID:MIME-Version:Content-Type; b=qZ08RkqOgBLmGnWpLhbMTRCZBKmZr2eIMoYu22Jnm6zDliuVUtBxGx0e0cKS9YyS+cww0HfGMUZT2nKS9MvP9lrcYhxc5Q+Z+YjPyJQE0qa3RYhuDWTiSblL8AudfmUdxKa3cQrasyMXTGKIut05ujBEkagagRPComyZ3XdcWMk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=XNMOZ07Y; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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="XNMOZ07Y" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791814090; 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; bh=QKzShl0BETKFb4agpoCsSYtnho7wDgym6Xjpb3K05rU=; b=XNMOZ07YesASl8qLyFzU9grUoGawwI2yHwaG5LMkmjcjI7nzcCmoOXETk/2eOwjdhdxhDw 8hM8gjDU4OjYAaNxrnlMh1DsJE8Mz78QN83r0lndRZ6DAho9w8Nk56K2Zcklv31N5KRnf0 IwqwkX34dbWr5rhpBT3BEXdC3ApDqXU= Received: from mx-prod-mc-01.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-146-NUf7G8ayM2WTcso2n1iO9A-1; Mon, 12 Oct 2026 14:08:03 +0000 X-MC-Unique: NUf7G8ayM2WTcso2n1iO9A-1 X-Mimecast-MFC-AGG-ID: NUf7G8ayM2WTcso2n1iO9A_1791814082 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7F708195FCC5; Mon, 12 Oct 2026 14:08:02 +0000 (UTC) Received: from mpatocka-thinkpadx1carbongen12.rmtcz.csb (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 191C430000E7; Mon, 12 Oct 2026 14:08:00 +0000 (UTC) Date: Mon, 12 Oct 2026 16:07:58 +0200 (CEST) From: Mikulas Patocka To: dm-devel@lists.linux.dev cc: Alasdair Kergon , Mike Snitzer , Benjamin Marzinski Subject: [PATCH] dm-bufio: fix non-working memory limit Message-ID: Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: aH1dXXxL79CPpXMudNnYPreP7ZUncsZgUcYtz4bMNGk_1791814082 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII The function evict_old is supposed to loop and evict buffers while the allocated size is above the threshold. However if it hits one bufio client that is empty, it stops and doesn't attempt to scan other clients. This commit fixes it, so that it skips empty clients and retries up to dm_bufio_client_count times. Fixes: 450e8dee51aa ("dm bufio: improve concurrent IO performance") Cc: stable@vger.kernel.org Signed-off-by: Mikulas Patocka Assisted-by: Claude:claude-opus-5 --- drivers/md/dm-bufio.c | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) Index: linux-2.6/drivers/md/dm-bufio.c =================================================================== --- linux-2.6.orig/drivers/md/dm-bufio.c +++ linux-2.6/drivers/md/dm-bufio.c @@ -2545,6 +2545,13 @@ struct dm_bufio_client *dm_bufio_client_ init_waitqueue_head(&c->free_buffer_wait); c->async_write_error = 0; + /* + * A client with no buffers yet is not holding the oldest buffer in + * the system; leaving this zeroed would claim exactly that and keep + * the client pinned at the front of dm_bufio_all_clients. + */ + c->oldest_buffer = jiffies; + c->dm_io = dm_io_client_create(); if (IS_ERR(c->dm_io)) { r = PTR_ERR(c->dm_io); @@ -2779,9 +2786,23 @@ static unsigned long __evict_a_few(unsig dm_bufio_unlock(c); - if (count) + if (count) { c->oldest_buffer = oldest_buffer; - __insert_client(c); + __insert_client(c); + } else { + /* + * We evicted nothing, so 'oldest_buffer' tells us nothing new + * and the client keeps its old, possibly very stale, value. + * Requeue it at the back rather than by that value, otherwise + * __insert_client() would put it straight back at the front + * and every subsequent call would pop this same client again, + * never reaching any of the others. + * + * This leaves the list slightly out of order, which is fine - + * it is only ever an approximation. + */ + list_add_tail(&c->client_list, &dm_bufio_all_clients); + } return count; } @@ -2806,11 +2827,23 @@ static void evict_old(void) { unsigned long threshold = dm_bufio_cache_size - dm_bufio_cache_size / DM_BUFIO_LOW_WATERMARK_RATIO; + int unproductive = 0; mutex_lock(&dm_bufio_clients_lock); while (dm_bufio_current_allocated > threshold) { - if (!__evict_a_few(64)) - break; + if (__evict_a_few(64)) { + unproductive = 0; + } else { + /* + * This client had nothing to give. Try the others + * before giving up: one idle client, or one whose + * buffers are all held, must not stop us evicting + * from everybody else. Stop once a whole sweep of + * the client list has freed nothing. + */ + if (++unproductive >= dm_bufio_client_count) + break; + } cond_resched(); } mutex_unlock(&dm_bufio_clients_lock);