Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp226846rdb; Mon, 22 Jan 2024 18:53:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IEhG/RrD9g+HKrgiZMN9Ed/no0Xiyqn5PWPo75A2as6ZHqNG1LPq3keHYQaP7d+JyaCVQq0 X-Received: by 2002:a2e:a583:0:b0:2cd:24db:4faf with SMTP id m3-20020a2ea583000000b002cd24db4fafmr2520056ljp.58.1705978421448; Mon, 22 Jan 2024 18:53:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705978421; cv=pass; d=google.com; s=arc-20160816; b=rHT+UWKYS0edoplHaOyP2KiUikgGzDiSOLuqH3J6x+MVeyCe3js7gTfXRz/wuEaZ4u fPlTiYie+vl/d+JtB+IdwbxY9SYfs8BfRVCBi5AJQvxNJwnruB8bqQvHGoHudQ4Fz3fm N8twgzS0jl06O+/mS2PpRQweV+vCmXQlfJOpLpDz4T3vUX4yLeGU2XHskVMa2Os7ZcIu B+1NVEztfrnqK4DDwqCUeCBx7PmUqFRitPVNZ0eXs2sPB0m4XEunmjOvdFX7Eo8iIl2w Y+1ACld5lfarXxac3MLDsiVBxmskY9Pdb5pDO2ACv7JBj4mCaNDy8VCPfTSDWGHWXMtZ EtyA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=uOBCaJ52Y1g1wzfxl07PVL77XlQF0EwMm9afVAokmvY=; fh=myjbA5NFqCnFaPBTfOgLZ19LgYJaa5ke5Dg3d+Y516g=; b=coYtR+XnvvZdCjsk7/j3YZUpTlChXbWILQLlF/5BmXZHjbwGNTPJ9otEyc4uW1npAP aJvqxqMrg03F7yfEcOfA6lb2FMKPMnTmSS/p7AuPko/Xhw27OaMfMGz/2aS+YhZI6D3l VMtWfXHAi7V6YZZByvMWmOD6Q4yKk99DRJGnOMYPN7BQ5FMiW9tjU6S3GjGEdtKORUlv 60agTZYw897u0t+tcaOMBmF2hqqAtRbDxCEFnrEEK3EsypcKb1JwckEaKe5EkCSVPVuU pRNSUifm2+C5VPy57Xe6CmhZis6KADuNoh9VYccJpuIm5EZbJiJrmw3OczsNQujL/pCt ESsw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ZLRAbMT5; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-34652-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34652-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a11-20020a509e8b000000b0055c4588ff40si1442482edf.476.2024.01.22.18.53.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 18:53:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34652-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ZLRAbMT5; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-34652-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34652-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 am.mirrors.kernel.org (Postfix) with ESMTPS id EB4E31F24FAF for ; Tue, 23 Jan 2024 02:53:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 247FB1102; Tue, 23 Jan 2024 02:53:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ZLRAbMT5" Received: from mail-ot1-f43.google.com (mail-ot1-f43.google.com [209.85.210.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E25E2811 for ; Tue, 23 Jan 2024 02:53:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705978413; cv=none; b=UuCNjRgotJ8+Z/1rC0nR0EDIJ9ACFmaEc3ldVlZ6IuCzikJDqowpFQjqDDkRF1V9Add6lz3WqcAyPWaWHMHsNMCm3+gV+YcYS/PDXjX9cS0LgG1j2FmySMkg2GvnJgvuW7v5hYkuYNNlS9pjqNXB1Pk8Cln78Ikuce2jpBP8Wyo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705978413; c=relaxed/simple; bh=cC55pTITuXahQpx5YCMQPJ0anjw73aDUUrh4ymutob4=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=k+nmor2gBQThKk9bTyGcgNbiTd0ZUxK0HGcXcGA3AybXXDutsof5IHU8vpb6Jnmvee+3LeoTBHlDB/gQcuprkl/rrwVvgBAE+7nBbhFdhRdO2bwcGG2MqGNUHO+xcuSeeUb+Av6uwl8J9UfuYeMpqOiBdCf27ONpND9/PZs65UQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ZLRAbMT5; arc=none smtp.client-ip=209.85.210.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ot1-f43.google.com with SMTP id 46e09a7af769-6e0eed0427cso995927a34.0 for ; Mon, 22 Jan 2024 18:53:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1705978411; x=1706583211; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=uOBCaJ52Y1g1wzfxl07PVL77XlQF0EwMm9afVAokmvY=; b=ZLRAbMT5C0b/oyf12DbDmWL8GIWiRrfHIy9CGljNLL4r3aMR/LPRALk47yABSsHYhl 3yfeMP9sCJLnO/gBJ9bjeCCWXPB75hM31//j2ojGFQtAFbknwOiGp8P1mCEVSdH+qtRp x6w59P8IO0WeNOx6tZ2NbanMPVVy7m92IvtrWv/UoFDG0UnBozdoC4o5smoY5WVzjLjC +K1JAz30qzDN8QRJPfURTz5o2LUYRN3OumEHfPmcHb+LFdw0w0bN8CIojAIxW05STwPn liM9EUn8WRrY8XNyXAzddhIKQPxhklSiRIaxf3aR96SCT5QtE7dD+ikgL0TabjaMCxNC nFOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705978411; x=1706583211; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uOBCaJ52Y1g1wzfxl07PVL77XlQF0EwMm9afVAokmvY=; b=OOPWzjWdbXYDeybOQykCQwY5b2XAhYQm5GAPzzFubJM6Dozv+4OQPQY1lG8z13+FT8 4s/FrxO2KjHnfvv172IQrEZtWLdz/2AD8cDIrJmhdNBNmZP6BDRAWbZ7iTAd1rfqNdgN rYm4bCHmbbdO/m1LvMt2g3KqmiXtSfhPVYlqOHYdsE+UHTjL0k/rSBWjd7s8gvE/BLAO E0/0T7c2fFpJ3KHFf/HWI0bI7KmZiqAPEXBwto2CDc1nr8edE+FADYcAUqiv0NpzI3Zh OB81PNCXsMDodtRn+Jb52l6/KfFUbi32Xqg6BIKaRxc/A3t6FkXOon/lsndCFW85ZTom r0hQ== X-Gm-Message-State: AOJu0YzuLuTv+IS0HXbhsnAlmNLy4g4A09TSOsmO9NZroIg+zLdekr5G ZZ2gtRWjiS8W5KsqkkThD0nemOCCwLfo9GevZJZkokq6YU5ht4q+ISQ6U2Wi2XWvm7oHfhbqljK /3OSN42BZ6eWgTl/4YOHzGJEe/THIVAXwa26z X-Received: by 2002:a05:6870:4624:b0:213:4043:aaf2 with SMTP id z36-20020a056870462400b002134043aaf2mr810089oao.83.1705978410832; Mon, 22 Jan 2024 18:53:30 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240117192534.1327608-1-dylanbhatch@google.com> <20240119141501.GA23739@redhat.com> <20240119141529.GB23739@redhat.com> <20240120204552.c0708fd10fc8e2442c447049@linux-foundation.org> <20240121120754.GA2814@redhat.com> In-Reply-To: <20240121120754.GA2814@redhat.com> From: Dylan Hatch Date: Mon, 22 Jan 2024 18:53:19 -0800 Message-ID: Subject: Re: [PATCH 2/2] getrusage: use sig->stats_lock To: Oleg Nesterov Cc: Andrew Morton , Kees Cook , Frederic Weisbecker , "Joel Fernandes (Google)" , Ard Biesheuvel , "Matthew Wilcox (Oracle)" , Thomas Gleixner , Sebastian Andrzej Siewior , "Eric W. Biederman" , Vincent Whitchurch , Dmitry Vyukov , Luis Chamberlain , Mike Christie , David Hildenbrand , Catalin Marinas , Stefan Roesch , Joey Gouly , Josh Triplett , Helge Deller , Ondrej Mosnacek , Florent Revest , Miguel Ojeda , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, Jan 21, 2024 at 4:09=E2=80=AFAM Oleg Nesterov wro= te: > > Dylan, do you have a better description? Can you share your repro? That description seems accurate to me. > although I think that something simple like > > #define NT BIG_NUMBER > > pthread_barrier_t barr; > > void *thread(void *arg) > { > struct rusage ru; > > pthread_barrier_wait(&barr); > for (;;) > getrusage(RUSAGE_SELF, &ru); > return NULL; > } > > int main(void) > { > pthread_barrier_init(&barr, NULL, NT); > > for (int n =3D 0; n < NT-1; ++n) { > pthread_t pt; > pthread_create(&pt, NULL, thread, NULL); > } > thread(NULL); > > return 0; > } > > should work if you have a machine with a lot of memory/cpus. > > Oleg. > Here's my repro, very similar to what you've sent: #define _GNU_SOURCE #include #include #include #include #include #include #include int thrd_func(void *data) { struct rusage usage; int *complete =3D (void *)data; while (!*complete); while (1) { getrusage(RUSAGE_SELF, &usage); } } #define STACK_SIZE (1024) int main(int argc, char **argv) { if (argc !=3D 2) { printf("Usage: %s \n", argv[0]); exit(EXIT_SUCCESS); } const int cnt =3D atoi(argv[1]); int pids[cnt]; int complete =3D 0; printf("Starting test with %d threads...\n", cnt); for (int i =3D 0; i < cnt; i++) { char *stack =3D mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE= , MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0); if (stack =3D=3D MAP_FAILED) { perror("mmap() failed\n"); return -1; } pids[i] =3D clone(thrd_func, stack + STACK_SIZE, CLONE_THREAD | CLONE_SIGHAND | CLONE_FS | CLONE_VM | CLONE_FILES, (void *) &complete); if (pids[i] =3D=3D -1) { perror("clone() failed\n"); return pids[i]; } } complete =3D 1; printf("waiting on threads...\n"); sleep(100); complete =3D 0; printf("test finished.\n"); exit(EXIT_SUCCESS); } I can't remember exactly why I chose to call mmap and clone directly instea= d of using pthreads... but I do know what mmap'ing in a smaller stack size makes the repro more reliable since you can create more threads. It seemed like around 250K threads was about enough to reliably produce the lockup, but your mileage may vary.