Home Ubuntu How to use preload to speedup app launches in Ubuntu

How to use preload to speedup app launches in Ubuntu

Preload is an intelligent tool that can significantly speed up application launch times in Ubuntu. This guide covers the basics of installing preload, configuring it to suit your usage patterns, and understanding how it works to pre-fetch and cache your most-used applications, leading to faster load times and a smoother user experience.

by John Horan
preload in ubuntu

In today’s fast-paced digital world, the speed at which applications launch can significantly impact our productivity and overall computing experience. For Linux users, there’s a powerful yet often underutilized tool that can make a noticeable difference in this area: preload. Preload is a daemon that intelligently analyzes your application usage patterns and preloads parts of frequently used programs into memory, reducing their load times.

In this blog, we delve into the intricacies of preload, exploring how it works, its installation and configuration process, and the practical benefits and limitations it brings to your system.

What is preload?

Preload is a daemon that runs in the background of your Linux system. It analyzes user behavior and tracks which applications are frequently used. Over time, it smartly predicts which applications you might launch next and loads parts of these applications into memory. This process reduces load times significantly, making your computing experience smoother and faster.

Why use preload?

Imagine clicking on your favorite software and having it pop up almost instantly. That’s the magic of preload! It’s particularly useful for systems with slower hard drives or for applications that typically take a long time to start.

How preload works

Preload monitors the applications you use and intelligently predicts what you might run next. It doesn’t load the entire application into memory, just the bits that are often needed. This approach ensures that memory usage is optimized without overburdening the system.

My experience

I remember using an older laptop that struggled with load times. After installing preload, the improvement was noticeable. Applications like GIMP and LibreOffice, which used to take a considerable time to launch, were ready in a fraction of the time.

Installing preload on Ubuntu

Step-by-step guide

  1. Open your terminal: You can do this by searching for ‘terminal’ in your application menu or using a shortcut, typically Ctrl + Alt + T.
  2. Install preload: Type the following command and hit enter:
    sudo apt-get install preload
    
  3. Check if preload is running: After installation, preload starts automatically. You can check its status with:
    systemctl status preload
    

Expected output

You should see an output indicating that preload is active and running.

● preload.service - LSB: Adaptive readahead daemon
Loaded: loaded (/etc/init.d/preload; generated)
Active: active (running) since Sun 2023-12-10 09:33:47 UTC; 1h 27min ago
Docs: man:systemd-sysv-generator(8)
Process: 1234 ExecStart=/etc/init.d/preload start (code=exited, status=0/SUCCESS)
Main PID: 1235 (preload)
Tasks: 1 (limit: 4915)
Memory: 10.2M
CGroup: /system.slice/preload.service
└─1235 /usr/sbin/preload

Dec 10 09:33:47 your-hostname systemd[1]: Starting LSB: Adaptive readahead daemon...
Dec 10 09:33:47 your-hostname preload[1234]: Starting preload: preload.
Dec 10 09:33:47 your-hostname systemd[1]: Started LSB: Adaptive readahead daemon.

Configuring preload

Preload works out of the box, but you can tweak its settings for better performance.

Sample configuration

Edit the preload configuration file by typing:

sudo nano /etc/preload.conf

Here, you can adjust settings like sortstrategy, minsize, and memtotal. For instance, changing minsize to a higher value means preload will only consider larger files, potentially speeding up larger applications.

Let’s go through a hypothetical example to illustrate this.

Original configuration (before)

Here’s an example of what the preload configuration file might look like in its default state:

# /etc/preload.conf - original configuration

sortstrategy = 0
minsize = 20000
memtotal = 50

In this default configuration:

  • sortstrategy is set to 0, meaning preload prioritizes files based on access frequency.
  • minsize is set to 20000 (bytes), so preload will consider files larger than 20 KB.
  • memtotal is set to 50, meaning preload can use up to 50% of the total RAM.

Adjusted configuration (after)

Now, let’s say you want to adjust these settings to focus more on larger files and allocate more memory to preload. Here’s how the configuration might look after your changes:

# /etc/preload.conf - adjusted configuration

sortstrategy = 1
minsize = 500000
memtotal = 70

In this adjusted configuration:

  • sortstrategy is changed to 1, which means preload will now prioritize smaller files first. However, given the significant increase in minsize, this change will mostly affect larger files.
  • minsize is increased to 500000 (bytes), so now preload will only consider files larger than 500 KB. This change ensures that preload focuses on larger files, which could be more impactful for speeding up the launch of large applications.
  • memtotal is increased to 70, allowing preload to use up to 70% of the total RAM for caching files. This increase gives preload more resources to cache the larger files you’re targeting.

After editing, save the file and restart preload:

sudo systemctl restart preload

Monitoring preload’s performance

To see how preload is impacting your system, you can check its log file:

cat /var/log/preload.log

Example output:

Sun Dec 10 09:33:47 2023: starting preload 0.6.4 daemon
Sun Dec 10 09:33:47 2023: monitoring 1234 files from 234 directories
Sun Dec 10 10:15:32 2023: re-scanning directories
Sun Dec 10 10:15:35 2023: re-scanning done, monitoring 1256 files from 237 directories
Sun Dec 10 11:00:01 2023: re-scanning directories
Sun Dec 10 11:00:04 2023: re-scanning done, monitoring 1260 files from 238 directories
Sun Dec 10 11:45:30 2023: re-scanning directories
Sun Dec 10 11:45:33 2023: re-scanning done, monitoring 1275 files from 240 directories

Understanding the output

  • Timestamps: Each entry is timestamped, showing when the action occurred.
  • Starting preload daemon: Indicates when the preload service started.
  • Monitoring files and directories: Shows the number of files and directories preload is monitoring. This number changes as preload adapts to your usage patterns.
  • Re-scanning directories: Periodically, preload rescans the directories to update its list of files based on recent usage.
  • Re-scanning done: Indicates the completion of a rescan and shows the updated count of files and directories being monitored.

What this tells you

This log provides insights into how preload is adapting to your system’s usage. By monitoring the changes in the number of files and directories, you can get a sense of how preload is optimizing its operations to better suit your usage patterns. Regular rescans ensure that preload remains up-to-date with the latest changes in your file access habits.

Pros and cons

Advantages

  1. Improved I/O efficiency: Preload reduces disk I/O at application start-up by intelligently preloading parts of frequently used applications into RAM. This is particularly beneficial for systems with mechanical hard drives, where I/O operations are a significant bottleneck.
  2. Adaptive learning algorithm: Preload uses a sophisticated algorithm to analyze usage patterns, adapting to changes in your application usage over time. This means that the more you use certain applications, the better preload becomes at predicting and loading the necessary files.
  3. Reduced application startup time: By having necessary files already loaded in memory, the time taken for applications to become responsive after launch is significantly reduced, enhancing user experience.
  4. Customizable performance tuning: Preload allows for fine-tuning of various parameters like minsize, memtotal, and sortstrategy, offering flexibility to optimize performance based on individual needs and system specifications.
  5. Low overhead: Despite running in the background, preload is designed to be lightweight. It doesn’t consume a significant amount of CPU resources, making it suitable even for less powerful systems.

Disadvantages

  1. Increased memory usage: Preload requires a portion of the system’s RAM to store preloaded files. On systems with limited memory, this could potentially lead to reduced available RAM for other applications, possibly affecting overall system performance.
  2. Diminishing returns on SSDs: Systems equipped with Solid State Drives (SSDs) may see less benefit from preload, as SSDs already provide fast read speeds. The impact of preload is more pronounced on systems with traditional hard drives.
  3. Potential for inaccurate predictions: While preload’s algorithm is generally effective, it’s not foolproof. There may be instances where it preloads files that are not needed, or fails to preload files that are needed, especially if user behavior changes rapidly.
  4. Requires time to learn: Preload needs time to analyze usage patterns before its effects become noticeable. New users or systems with freshly installed preload won’t see immediate performance improvements.
  5. Limited to Linux environments: Preload is primarily a Linux-based tool, which means its benefits are not available to users of other operating systems like Windows or macOS.

Technical considerations

  • Balancing memory usage: Users need to balance the memory allocated to preload (via memtotal) with the overall system memory, ensuring that there’s enough RAM left for other applications and system processes.
  • File size considerations: The minsize parameter should be configured based on the typical size of files used by your most-used applications. Setting it too high or too low can impact preload’s effectiveness.
  • System monitoring: Users should monitor system performance metrics like RAM usage, disk I/O, and application startup times to assess the impact of preload and adjust configurations as needed.

Commands summary

Command Description/Effect
sudo apt-get install preload Installs the preload daemon on your system.
systemctl status preload Checks the current status of the preload service, showing whether it’s active and running.
sudo nano /etc/preload.conf Opens the preload configuration file for editing. This is where you can change settings like sortstrategy, minsize, and memtotal.
sudo systemctl restart preload Restarts the preload service to apply any changes made in the configuration file.
cat /var/log/preload.log Displays the preload log file, showing which files have been preloaded and other operational details.

Conclusion

The key to harnessing the full potential of preload lies in thoughtful configuration and understanding its impact on system resources. Adjusting settings like sortstrategy, minsize, and memtotal allows users to tailor preload’s behavior to their specific needs. However, it’s important to balance these settings with the overall system performance, keeping in mind that preload’s learning algorithm requires time to adapt to usage patterns.

Having explored the depths of preload, it’s clear that this tool offers a valuable enhancement to the Linux computing experience, particularly for systems with slower hard drives. By intelligently preloading parts of applications based on user behavior, preload can significantly reduce application launch times, making your workflow smoother and more efficient. While it shines in environments with ample RAM and traditional hard drives, its effectiveness may vary on systems with limited memory or those using SSDs.

You may also like

Leave a Comment

fl_logo_v3_footer

ENHANCE YOUR LINUX EXPERIENCE.



FOSS Linux is a leading resource for Linux enthusiasts and professionals alike. With a focus on providing the best Linux tutorials, open-source apps, news, and reviews written by team of expert authors. FOSS Linux is the go-to source for all things Linux.

Whether you’re a beginner or an experienced user, FOSS Linux has something for everyone.

Follow Us

Subscribe

©2016-2023 FOSS LINUX

A PART OF VIBRANT LEAF MEDIA COMPANY.

ALL RIGHTS RESERVED.

“Linux” is the registered trademark by Linus Torvalds in the U.S. and other countries.