Skip to contentSkip to conversation

tmpfs time granularity fix for [acm]time moving backwards.

PATCH In review Robin H. Johnson 2 participants 3 messages Jun 9, 2006 – Jun 11, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tmpfs time granularity fix for [acm]time moving backwards.

[Please CC me on replies].

I noticed a strange behavior in a tmpfs file system the other day, while building packages - occasionally, and seemingly at random, make decided to rebuild a target. However only on tmpfs.

A file would be created, and if checked, it had a sub-second timestamp. However, after an utimes related call where sub-seconds should be set, they were zeroed instead. In the case that a file was created, and utimes(...,NULL) was used on it in the same second, the timestamp on the file moved backwards.

Puesdo-code of my testcase:

	int fd = creat(name,0644);
	fstat(fd,&st);
	printf("...[acm]time...",...)
	futime(fd,NULL);
	fstat(fd,&st);
	printf("...[acm]time...",...)
	close(fd);

Tested against: linus 2.6.13, linus 2.6.17-rc6.

Test output from a filesystem not supporting sub-second timestamps (ext3, reiserfs):

creat:   m=1149891410.0 c=1149891410.0 a=1149891407.0
futimes: m=1149891410.0 c=1149891410.0 a=1149891410.0

Test output from a filesystem supporting sub-second timestamps (jfs,xfs,ramfs):

creat:   m=1149891452.928796249 c=1149891452.928796249 a=1149891452.928796249
futimes: m=1149891452.928796249 c=1149891452.928796249 a=1149891452.928796249

Test output from the tmpfs filesystem before the fix:

creat:   m=1149892052.562029884 c=1149892052.562029884 a=1149892052.562029884
futimes: m=1149892052.0         c=1149892052.0         a=1149892052.0

Test output from the tmpfs filesystem with the patch below:

creat:   m=1149892086.382150894 c=1149892086.382150894 a=1149892075.473249075
futimes: m=1149892086.383150885 c=1149892086.383150885 a=1149892086.383150885

After some digging, I found that this was being caused by tmpfs not having a time granularity set, thus inheriting the default 1s granularity.

NOTE: This also indicates there is another bug at the VFS layer, where the initial timestamp did not have the granularity applied to it.

mm/shmem.c +1 -0
@@ -2102,6 +2102,7 @@ #endif
 	sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
 	sb->s_magic = TMPFS_MAGIC;
 	sb->s_op = &shmem_ops;
+	sb->s_time_gran = 1;
 
 	inode = shmem_get_inode(sb, S_IFDIR | mode, 0);
 	if (!inode)
Signature · 3 lines
Robin Hugh Johnson
E-Mail     : [email protected]
GnuPG FP   : 11AC BA4F 4778 E3F6 E4ED  F38E B27B 944E 3488 4E85
#1 lore raw
Quoted 9 lines

Test output from a filesystem supporting sub-second timestamps (jfs,xfs,ramfs):

creat:   m=1149891452.928796249 c=1149891452.928796249 a=1149891452.928796249
futimes: m=1149891452.928796249 c=1149891452.928796249 a=1149891452.928796249

Test output from the tmpfs filesystem with the patch below:

creat:   m=1149892086.382150894 c=1149892086.382150894 a=1149892075.473249075
futimes: m=1149892086.383150885 c=1149892086.383150885 a=1149892086.383150885

Is it normal that creat and futimes match for jfs/xfs?

Quoted 2 lines

Hint: Cc it to the shmem.c maintainer, or it may get missed :)

Jan Engelhardt

#2 lore raw
Quoted 9 lines · Jan Engelhardt
Quoted 8 lines

Test output from a filesystem supporting sub-second timestamps (jfs,xfs,ramfs):

creat:   m=1149891452.928796249 c=1149891452.928796249 a=1149891452.928796249
futimes: m=1149891452.928796249 c=1149891452.928796249 a=1149891452.928796249

Test output from the tmpfs filesystem with the patch below:

creat:   m=1149892086.382150894 c=1149892086.382150894 a=1149892075.473249075
futimes: m=1149892086.383150885 c=1149892086.383150885 a=1149892086.383150885

Is it normal that creat and futimes match for jfs/xfs?

My testcase just seemed to run nice and fast there, if I do some work in the middle or sleep, the numbers will be different more, but otherwise I think it implies that both operations are taking place during the same time instance (I have HZ=1000 as you may be able to deduce by the 1ms differences in some of the pairs).

I ran it a few more times on ramfs for good measure.
creat: m=1150025153.933532153 c=1150025153.933532153 a=1150025151.29558289
futimes: m=1150025153.933532153 c=1150025153.933532153 a=1150025153.933532153
...
creat: m=1150025156.860505810 c=1150025156.860505810 a=1150025153.933532153
futimes: m=1150025156.861505801 c=1150025156.861505801 a=1150025156.861505801
...
creat: m=1150025247.906686387 c=1150025247.906686387 a=1150025247.459690410
futimes: m=1150025247.907686378 c=1150025247.907686378 a=1150025247.907686378

Quoted 2 lines
Quoted 1 line

Hint: Cc it to the shmem.c maintainer, or it may get missed :)

Will do, thanks.

Signature · 3 lines
Robin Hugh Johnson
E-Mail     : [email protected]
GnuPG FP   : 11AC BA4F 4778 E3F6 E4ED  F38E B27B 944E 3488 4E85