Skip to contentSkip to conversation

Avoid doubling the efforts for /var/log/journal

PATCH Dr. Werner Fink 1 participant 1 message Jun 18, 2014 3 messages not in the archive Btrfs file system

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw
Quoted 55 lines · Cristian Rodríguez
Quoted 19 lines · Werner Fink

That is: set NOATIME, NOCOW, and NOCOMP for the journal directory

---
 src/journal/journald-server.c |   29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)
journal/journald-server.c +1 -0
index eda5dcf..37d6dc3 100644
@@ -21,6 +21,7 @@
 
 #include <sys/signalfd.h>
 #include <sys/ioctl.h>
+#include <linux/fs.h>
 #include <linux/sockios.h>
 #include <sys/statvfs.h>
 #include <sys/mman.h>

journal/journald-server.c finish: · line 924

Quoted 5 lines
journal/journald-server.c +1 -1
@@ -920,7 +921,7 @@ finish:
 
 
 static int system_journal_open(Server *s) {
-        int r;
+        int r, fd;

_cleanup_close_ ...

journal/journald-server.c finish:

Quoted 7 lines
journal/journald-server.c +7 -0
+                /*
+                 * On journaling and/or compressing file systems avoid doubling the
+                 * efforts for the system, that is set NOCOW and NOCOMP inode flags.
+                 * Check for every single flag as otherwise some of the file systems
+                 * may return EOPNOTSUPP on one unkown flag (like BtrFS does).
+                 */
+                if ((fd = open(fn, O_DIRECTORY)) >= 0) {

O_CLOEXEC...

Quoted 6 lines
journal/journald-server.c +6 -0
+                        long flags;
+                        if (ioctl(fd, FS_IOC_GETFLAGS, &flags) == 0) {
+                                int old = flags;
+                                if (!(flags&FS_NOATIME_FL) && ioctl(fd, FS_IOC_SETFLAGS, flags|FS_NOATIME_FL) == 0)
+                                        flags |= FS_NOATIME_FL;
+                                if (!(flags&FS_NOCOW_FL) && ioctl(fd, FS_IOC_SETFLAGS, flags|FS_NOCOW_FL) == 0)

journal/journald-server.c

Quoted 10 lines
journal/journald-server.c +10 -0
+                                        flags |= FS_NOCOW_FL;
+                                if (!(flags&FS_NOCOMP_FL) && s->compress) {
+                                        flags &= ~FS_COMPR_FL;
+                                        flags |= FS_NOCOMP_FL;
+                                }
+                                if (old != flags)
+                                        ioctl(fd, FS_IOC_SETFLAGS, flags);
+                        }
+                        close(fd);
+                }
Quoted 2 lines

I agree that this should be done, however I remain unconvinced this is the right place to do it..

IMHO this is the correct place as it helps to speed up systemd-journal on BtrFS. This was the reason for this patch and is tested even if the patch does not use _cleanup_close_ and O_CLOEXEC ;)

Werner

Signature · 2 lines
  "Having a smoking section in a restaurant is like having
          a peeing section in a swimming pool." -- Edward Burr